I like to know the solution to my problem.
I'm using while loop to get results of number of rows, but I like to display this in one row and be able to make a variable from this result.
On the screen everything look greate but the result is going to db in number of rows.
What is wrong?
This is my code:
$items = explode("&", $basket);
for ($i = 0; $i < count($items)-1; $i++) {
// Get the products name from the database...
$sql="SELECT name FROM product WHERE productid=$items[$i] ORDER BY name ";
$result = @mysql_query("$sql",$db);
$num = @mysql_num_rows($result);
if(list($name) = @mysql_fetch_array($result)){
$res1 .= " $name";
echo"$res1";
}
$db = @mysql_connect("localhost", "localroot", "localpassword");
@mysql_select_db("mydb");
$sql = "INSERT INTO orders ( orderid, products)
VALUES ('0','$res1')";
$result = @mysql_query("$sql",$db);
$orderid = @mysql_insert_id();
}
Will be very pleased if someone my help.
evie
I'm using while loop to get results of number of rows, but I like to display this in one row and be able to make a variable from this result.
On the screen everything look greate but the result is going to db in number of rows.
What is wrong?
This is my code:
$items = explode("&", $basket);
for ($i = 0; $i < count($items)-1; $i++) {
// Get the products name from the database...
$sql="SELECT name FROM product WHERE productid=$items[$i] ORDER BY name ";
$result = @mysql_query("$sql",$db);
$num = @mysql_num_rows($result);
if(list($name) = @mysql_fetch_array($result)){
$res1 .= " $name";
echo"$res1";
}
$db = @mysql_connect("localhost", "localroot", "localpassword");
@mysql_select_db("mydb");
$sql = "INSERT INTO orders ( orderid, products)
VALUES ('0','$res1')";
$result = @mysql_query("$sql",$db);
$orderid = @mysql_insert_id();
}
Will be very pleased if someone my help.
evie