You're still not doing that...jackpf wrote:You need to put "or die(mysql_error())" after all queries and connections...which you have not done...
Reading from a database
Moderator: General Moderators
Re: Reading from a database
Re: Reading from a database
i dont understand where Exactly in the code to put it?
Re: Reading from a database
Code: Select all
$sql = mysql_query("SHOW TABLES;")or die(mysql_error());
while($fetch = mysql_fetch_array($sql)or die(mysql_error()))
{
$sql2 = mysql_query("SELECT * FROM $fetch[0] ORDER BY dateadded DESC LIMIT 5")or die(mysql_error());
while($row = mysql_fetch_array($sql2)or die(mysql_error()))
{
echo "<div id= \"latest10\">". "<li>". "<h3 class=\"h3cap\">". "<span>". $row['first']. " ". $row['last']. "</span>". "<span style=\"float:right;\">". " [". $row['id']. "]". "</span>". "</h3>". "<p class=\"paragraph\">". $row['story']. "</p>". "</br>". "<p style=\"text-align:right;font-size:11px;\">". "Added: ". $row['dateadded']. "</p>". "</li>". "</div>";
}
}
mysql_close($con);
?>it seems to be working !!!
thank you thank you thank you !!!!
Re: Reading from a database
Oh yeah, I see it working now.
Btw, you don't want to use the "or die..." with mysql_fetch_array() since it will return false when the result set is empty, triggering an error that doesn't exist.
Also, I was just wondering, why do you need to do this? Don't you have all your news stories in one table?
Btw, you don't want to use the "or die..." with mysql_fetch_array() since it will return false when the result set is empty, triggering an error that doesn't exist.
Also, I was just wondering, why do you need to do this? Don't you have all your news stories in one table?
Re: Reading from a database
Actually, you don't want to use die() as a error handler in a real application, ever. Unless this is some exercise script, I would strongly advise against it.you don't want to use the "or die..."
Re: Reading from a database
No, you should use trigger_error() and error handling, but I was trying to help him resolve his errors....
Re: Reading from a database
Yeah, I know - I'm making sure he doesn't make this common practice. you probably don't want to trigger an error either, better to log silently and show an error page instead. Better than a blank screen or an internal error message
Re: Reading from a database
thank you very much both of you !! 
but i think there one more problem to look at.
Basically, I have done the code:
the code is shown here: http://www.selfamusingstories.elementfx.com/index.php
it does work, but for some reason only for the table 'family_stories' rather than for these too :
friends_stories
home_stories
strangers_stories
transport
work_stories
i think it is because its the first table in my list but i am not sure.
It does select all rows in the table 'family_stories' but not all of the Tables And Rows ?
I'm sorry to keep hastling you but i really have no idea what to do ?
please help

but i think there one more problem to look at.
Basically, I have done the code:
Code: Select all
<?php
$con = mysql_connect("localhost","user","pwd");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("dbname", $con);
$sql = mysql_query("SHOW TABLES;")or die(mysql_error());
while($fetch = mysql_fetch_array($sql)or die(mysql_error()))
{
$sql2 = mysql_query("select * from " . $fetch[0] . " ORDER BY dateadded DESC LIMIT 5")or die(mysql_error());
while($row = mysql_fetch_array($sql2)or die(mysql_error()))
{
echo "<div id= \"latest10\">". "<li>". "<h3 class=\"h3cap\">". "<span>". $row['first']. " ". $row['last']. "</span>". "<span style=\"float:right;font-size:14px;\">". " [". $row['id']. "]". "</span>". "</h3>". "<p class=\"paragraph\">". $row['story']. "</p>". "</br>". "<p style=\"text-align:right;font-size:10px;\">". "Added: ". $row['dateadded']. "</p>". "</li>". "</div>";
}
}
mysql_close($con);
?>it does work, but for some reason only for the table 'family_stories' rather than for these too :
friends_stories
home_stories
strangers_stories
transport
work_stories
i think it is because its the first table in my list but i am not sure.
It does select all rows in the table 'family_stories' but not all of the Tables And Rows ?
I'm sorry to keep hastling you but i really have no idea what to do ?
please help
Re: Reading from a database
Well, with trigger_error() and set_error_handler() you can do just that. Just out of interest, how would you do it?pytrin wrote:Yeah, I know - I'm making sure he doesn't make this common practice. you probably don't want to trigger an error either, better to log silently and show an error page instead. Better than a blank screen or an internal error message
And did you remove the or die() from mysql_fetch_array()? Because looking at your source code and the way it ends abruptly, to me it suggests that you haven't.
Also, you do realise that it's not going to select 5 stories, rather 5 stories from every table right?
Re: Reading from a database
i just removed or die() from mysql_fetch_array() but i get this error 'Unknown column 'dateadded' in 'order clause'' (without outer ' marks)And did you remove the or die() from mysql_fetch_array()? Because looking at your source code and the way it ends abruptly, to me it suggests that you haven't.
Also, you do realise that it's not going to select 5 stories, rather 5 stories from every table right?
and its fine it selects 5 stories from every table, i can modify later
thanks again but what do i do ?
Re: Reading from a database
Does dateadded exist in every table?
Re: Reading from a database
Those functions (mysql_connect,mysql_query) don't actually throw an error. You can simply test to see if they return false and act appropriately.Well, with trigger_error() and set_error_handler() you can do just that. Just out of interest, how would you do it?
Re: Reading from a database
well i feel like a di*k
in family_stories its 'dateadded' and the rest 'date added' :O
IT WORKED !!!!!!!!!!!!
:):):):):):):):):):):):):):):):)
thanks you so much guys ive been working on this for days !!!

IT WORKED !!!!!!!!!!!!
thanks you so much guys ive been working on this for days !!!
Re: Reading from a database
No problem.
I think you need to learn to debug your code a bit better though....
I think you need to learn to debug your code a bit better though....
Re: Reading from a database
jackpf wrote:No problem.
I think you need to learn to debug your code a bit better though....
how do you mean ?