Jump to content

[SOLVED] easy mysql query- error


ohdang888

Recommended Posts

i am learning MySQL and PHP. i created a very simple code here. in the table "test" from the database "realted"... there is one column of info, called "name"... there are 11 rows of data, each one has chacaters in it.

 

but the results its showing is just 11 blank rows (the rows were created on the page, i can highlight them) why is the info not coming up?

 

<?php
mysql_connect("----", "----", "----") or die(mysql_error());
mysql_select_db("related") or die(mysql_error());

$result = mysql_query("SELECT * FROM test")
or die(mysql_error());  

$row = mysql_fetch_array( $result );
while($row = mysql_fetch_array($result)){
echo $row['name'];
echo "<br>";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/83245-solved-easy-mysql-query-error/
Share on other sites

so... this?

<?php
mysql_connect("localhost", "root", "pancakes1") or die(mysql_error());
mysql_select_db("related") or die(mysql_error());
$result = mysql_query("SELECT * FROM test")
or die(mysql_error());  
//$row = mysql_fetch_array( $result );
while($row = mysql_fetch_array($result)){
echo $row['name'];
echo '<br>';
}
?>

 

that didn;t do anything at all. besudes, doesn't $row need to be specified about what it is???

ok thanks.

i have anoher question though...

 

this is new new query

$result = mysql_query("SELECT * FROM test ORDER BY RAND(id) LIMIT 5")

i want to pick 5 random ones and randomize their order. thorpe. in a previous forum, told me to add "ORDER BY RAND(id) LIMIT 5", but i am getting this error:

 

Unknown column 'id' in 'order clause'

 

whats wrong with the ID?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.