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
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???

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.