Networking North Dakota Here Service Your Computer Here
AmegA Design - You Be Creative - We will help you create it! Computers For Kids North Dakota
AmegA Web Design, & Bulk Ink Systems
New and Used Computers and equipment in North Dakota Tutoring for Windows based PC's
AmegA News Letter and Information STOP BUYING EXPENSIVE INK CARTRIDGES!
Streaming Internet Communication is the Future  
  Streaming Internet Communication is the Future
 
Streaming Internet Communication is the Future

Thank You Web Monkey
http://www.webmonkey.com
I Have made a copy of these how to dues because of the awesome direction it gives for php learning

Web Monkey PHP

 


PHP
By Web Monkey

Page 2 — Stay Informed

--------------------------------------------------------------------------------

Take a look at this script.

<html>

<body>

<?php

$db = mysql_connect("localhost", "root");

mysql_select_db("mydb",$db);

$result = mysql_query("SELECT * FROM employees",$db);

if ($myrow = mysql_fetch_array($result)) {

echo "<table border=1>\n";

echo "<tr><td>Name</td><td>Position</td></tr>\n";

do {

printf("<tr><td>%s %s</td><td>%s</tr>\n", $myrow["first"], $myrow["last"], $myrow["address"]);

} while ($myrow = mysql_fetch_array($result));

echo "</table>\n";

} else {

echo "Sorry, no records were found!";

}

?>

</body>

</html>


There are a number of new features introduced here, but they're quite simple. First, there's the mysql_fetch_array() function. This is exactly the same as mysql_fetch_row() with one nice exception: Using this function, we can refer to fields by their names (such as $myrow["first"]) rather than their numbers. This should save us some headaches. We've also introduced a do/while loop and an if-else statement.

The if-else statement says that if we can assign a row to $myrow, then continue; otherwise skip to the else section and do what's in there.

The do/while loop is a variation of the while() loop we used on the last page. We need the do/while loop here for a very good reason: With the initial if statement, we assigned the first row returned by the query to the variable $myrow. If at this point we executed a regular while statement (such as while ($myrow = mysql_fetch_row($result)), we'd be kicking the first record out of the variable and replacing it with the second record. But the do/while loop lets us test the condition after the code has been run once. So there's no chance of us accidentally skipping a row.

Finally, if there are no records returned at all, the statements contained in the else{} portion will be executed. To see this portion in action, change the SQL statement to SELECT * FROM employees WHERE id=6 or something else that will return no records.

Now let's extend this looping and if-else code to make one fancy-schmancy page. You're going to love it.

next page»






  Streaming Internet Communication is the Future
  Streaming Internet Communication is the Future
 
Streaming Internet Communication is the Future

Thank You Web Monkey
http://www.webmonkey.com
I Have made a copy of these how to dues because of the awesome direction it gives for php learning

Web Monkey PHP

 



AmegA Home 1910 E Front Ave Bismarck, ND

1910 E Front Ave - Bismarck, ND
701-223-9694
HOME * NETWORKING * SERVICE * SALES * TUTORING * WEB DESIGN * COMPUTERS FOR KIDS * NEWSLETTER * CONTINUOUS INK MACHINE SYSTEM * VIDEO EMAIL * CONTACT US HERE
Would You Like To Hear Some Silly Commercials That AmegA Has Placed On Some Cool Radio Stations Here
Bill Straily& Scott MC Gowen At Cumulus - Jason Huber & The B Man at Clear Channel
Commercials
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17