-6

I am trying to select a table and I don't know what I am doing wrong:

$result = mysql_query('SELECT * FROM sfat WHERE done="0" LIMIT 0,10');
$row = mysql_fetch_array($result)
$url = $row["web"];
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • You are using [an **obsolete** database API](http://stackoverflow.com/q/12859942/19068) and should use a [modern replacement](http://php.net/manual/en/mysqlinfo.api.choosing.php). – Quentin Dec 10 '13 at 12:09
  • 2
    SELECT statement does not CREATE a database – Royal Bg Dec 10 '13 at 12:09
  • 2
    `i dont know what i do wrong`.And whats is wrong.?What is the exact problem.? – 웃웃웃웃웃 Dec 10 '13 at 12:09
  • Maybe learn some MySQL first? The above query has zero in common with creating a database. For that you will need CREATE DATABASE (http://dev.mysql.com/doc/refman/5.0/en/create-database.html) but chances are you won't have sufficient privileges to create a database that way. –  Dec 10 '13 at 12:09
  • Your title and code does not match – Suresh Kamrushi Dec 10 '13 at 12:11
  • what you want create or select ? – naveen goyal Dec 10 '13 at 12:12
  • well, i refresh the php page but it doesn;t do nothing.. – user3086740 Dec 10 '13 at 12:12
  • What is your expected result? – Royal Bg Dec 10 '13 at 12:13
  • i want to extract from database more links and edited them – user3086740 Dec 10 '13 at 12:13
  • So for extracting you are going to the right direction. But, you first need to connect to the database. It was already mentioned that you need to use another DB API, however, with the one you are using, you first need to use mysql_connect, afterwards to test if mysql_query() failed, or if it returns more than zero rows (mysql_num_rows). In one of the answer a while loop was mentioned. It's common usage while using `(mysql_fetch_*)` to extract all the results. – Royal Bg Dec 10 '13 at 12:15

2 Answers2

1

use

while ($row = mysql_fetch_array($result) ) {
    $url = $row["web"];
    echo $url;
}

in stead of

$row = mysql_fetch_array($result)
$url = $row["web"];

Because your query indicates you are expecting up to 10 rows. But your code will only show the first one.

nl-x
  • 11,762
  • 7
  • 33
  • 61
0

The following example will be used to create database

<?php
$con=mysqli_connect("hostname","username","password");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

// Create database
$sql="CREATE DATABASE my_db";
if (mysqli_query($con,$sql))
  {
  echo "Database my_db created successfully";
  }
else
  {
  echo "Error creating database: " . mysqli_error($con);
  }
?> 
praveen
  • 286
  • 1
  • 8