PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?php
include "config.php";
$table = "tblBooks";
// connect to the mysql server
$link = mysql_connect($server, $db_user, $db_pass)
or die ("Could not connect to mysql because ".mysql_error());
// select the database
mysql_select_db($database)
or die ("Could not select database because ".mysql_error());
// read data from database
$result = mysql_query("SELECT * FROM $table WHERE 1 LIMIT 0 , 30")
or die ("Could not read data because ".mysql_error());
// print the data in a table
if (mysql_num_rows($result)) {
print "<table cellpadding=2 cellspacing=0 border=0 width=\"100%\">\n";
while ($qry = mysql_fetch_array($result)) {
print "<tr>$qry[Author]</tr>";
print "<tr>$qry[Title]</tr>";
}
print "</table>\n";
}
mysql_close();
?>
since you are getting any error messages I suppose the connection and queries are OK.
Try putting an else clause in the if (mysql_num_rows($result)) -in fact I think if($result) would work as well- so that you can see if the query is actually returning any records or not.
Another thing is that you are starting to print out '<table>' etc without including them in '<html><body>' elements
<html>
<body>
<?php
include "config.php";
$table = "tblBooks";
// connect to the mysql server
$link = mysql_connect($server, $db_user, $db_pass)
or die ("Could not connect to mysql because ".mysql_error());
// select the database
mysql_select_db($database)
or die ("Could not select database because ".mysql_error());
// read data from database
$result = mysql_query("SELECT * FROM $table")
or die ("Could not read data because ".mysql_error());
// print the data in a table
if (mysql_num_rows($result)) {
print "<table cellpadding=2 cellspacing=0 border=0 width=\"100%\">\n";
while ($qry = mysql_fetch_array($result)) {
print "<tr>$qry[Author]</tr>";
print "<tr>$qry[Title]</tr>";
}
print "</table>\n";
}
mysql_close();
?>
</body>
</html>
Also could you give me an example of the mentioned ELSE clause?
Either that or before printing "<table cellpadding=2 cellspacing=0 border=0 width=\"100%\">" print "<html><body>"
and also where you do (print "<tr>$qry[Author]</tr>";) do (print "<tr><td>$qry[Author]<td></tr>";)
as for the else clause I suggested that for debugging, so you can do:
Tried your suggestions and still not working! I just can't see whats wrong. No error is generated from the error handling so I guess the it is returning records.
I am now getting an error message
Parse error: parse error, unexpected T_PRINT in /usr/local/psa/home/vhosts/rrbltd.com/httpdocs/Development/Read_Cataloguev2.php on line 22
<?php
include "config.php";
$table = "tblBooks";
// connect to the mysql server
$link = mysql_connect($server, $db_user, $db_pass)
or die ("Could not connect to mysql because ".mysql_error());
// select the database
mysql_select_db($database)
or die ("Could not select database because ".mysql_error());
// read data from database
$result = mysql_query("SELECT * FROM $table")
or die ("Could not read data because ".mysql_error());
// print the data in a table
if (mysql_num_rows($result)) {
print "<html><body>"
print "<table cellpadding=2 cellspacing=0 border=0 width=\"100%\">\n";
while ($qry = mysql_fetch_array($result)) {
print "<tr>$qry[Author]</tr>";
print "<tr><td>$qry[Author]<td></tr>";
print "</table>\n";
print "</html></body>"
}
else {
echo 'If statementis not valid, no records returned';
}
mysql_close();
?>
Once again thanks for your time and patience.[/quote]
You forgot to end the print "<html><body>" with a semicolon
On line 21 it should be print "<html><body>";
The same applies where yoou close those tags {print "</body></html>";}
$somearray = array("1", "2,"3,"4");
for($i =0; $i < count($somearray); $i++){
echo $somearray[i];//I put this instead of $somearray[b][$i][/b] and it never showed me a error but wont display anything
}