Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

PHP with MySQL

Name: Anonymous 2010-12-16 8:44

So... here is my code:

mysql_select_db("mydb");

$SQLstring = "SELECT FANID, NAME, CITY, EMAIL FROM FANS;";

$QueryResult = mysql_query($SQLstring)

     Or die("<P>Unable to execute the query</P>" .

          "<P>Error code " . mysql_errno($DBConnect) .

            " : " . mysql_error($DBConnect) . "</P>");

echo "<P>$QueryResult</P>";


What do I have to echo to get it to print out the entire table? (It's only 4 entries)

Name: Anonymous 2010-12-16 8:49

PHP
Now you have two problems.
with MySQL
Now you have three problems.
$SQLstring not escaped
Now you have infinite problems.
What do I have to echo to get it to print out the entire table? (It's only 4 entries)
Forget it, it's NP-complete.

Name: Anonymous 2010-12-16 8:51

Does it print only the first row?

Name: Anonymous 2010-12-16 8:52

>>2

Well that's, um...helpful?

Name: Anonymous 2010-12-16 8:56

All it prints out is:
Resource id #3

Name: Anonymous 2010-12-16 9:03

I got it... there is no magical command to print an entire table, I need to step through each row with a loop, and print the contents of that row, specifying each table element for the columns:


$Row = mysql_fetch_row($QueryResult);

echo "<TR><TD>FanID</TD><TD>Name</TD><TD>City</TD><TD>Email</TD></TR>";
do
{
  echo "<TR><TD>{$Row[0]}</TD><TD>{$Row[1]}</TD><TD>{$Row[2]}</TD><TD>{$Row[3]}</TD></TR>";
  $Row = mysql_fetch_row($QueryResult);
} while ($Row);

Name: Anonymous 2010-12-16 9:03

Forgot the line breaks and spaces, but you get the idea

Name: Anonymous 2010-12-16 9:07

>>6
<init>
do {
   <expr>
   <incr>
} while (<cond>);


Use a for loop for readability.

Name: Anonymous 2010-12-16 9:08

>>6
GENIUS!

Name: Anonymous 2010-12-16 10:49

>>9
Nested loops what'll they think up next?

Name: Anonymous 2010-12-16 20:27


for ($i=0; $Row = mysql_fetch_row($QueryResult); $i++) {
  if (i === 0) {
    echo "<TR><TD>FanID</TD><TD>Name</TD><TD>City</TD><TD>Email</TD></TR>";
  } else {
    echo "<TR><TD>{$Row[0]}</TD><TD>{$Row[1]}</TD><TD>{$Row[2]}</TD><TD>{$Row[3]}</TD></TR>";
  }
  $Row = mysql_fetch_row($QueryResult);
}

Name: Anonymous 2011-02-03 4:37

Don't change these.
Name: Email:
Entire Thread Thread List