...

View Full Version : MYSQL database not loading, and stopping general page from loading!



THM
11-28-2006, 01:24 AM
<?PHP
include("$connect");

$sql = "SELECT * FROM `TABLE_pm` WHERE touser = '".$_SESSION['username']."' LIMIT 0 , 30";
while ($r = mysql_query($sql))

$to = $r['touser'];
$from = $r['fromuser'];
$subject = $r['subject'];
$date = $r['date'];
$msg = $r['message'];

echo "$to";

?>


any ideas on whats wrong? Its not only that it won't work, but the page won't even load with this code in there. Is there something I'm doing drastically wrong? Please get back to me on your own time, when its good for you. Thank you.

Ok, new way of it loading. NOW its trying to get me to download the page.

chump2877
11-28-2006, 01:27 AM
Can you post the exact error message that you are getting?

THM
11-28-2006, 01:28 AM
It is not an error message, its just either taking forever to load, or trying to get me to download it. It seems to be the while tag, so i'm wondering if their is another way to do this besides that?

chump2877
11-28-2006, 01:31 AM
Post the full code then...

and you're missing opening and closing brackets for your while loop:

<?PHP
include("$connect");

$sql = "SELECT * FROM `TABLE_pm` WHERE touser = '".$_SESSION['username']."' LIMIT 0 , 30";
while ($r = mysql_query($sql))
{
$to = $r['touser'];
$from = $r['fromuser'];
$subject = $r['subject'];
$date = $r['date'];
$msg = $r['message'];

echo "$to";

}

?>

Edit: Also, wild guess, you might be having problems withthis line:

include("$connect");

Try substituting $connect with the actual file/path name, like this:

include '/path/file.php';

THM
11-28-2006, 01:53 AM
it is an actual directory, i just don't want to post it on here because.. well, i've heard you should give as little as you can, by replacing with variables and such.

Also, I am going to try that. I'll see if it works.

UPDATE
Nope, It didn't work. Its making me try and download it again. And that is the full code for now, I am just starting but i want to get the tables working right first.

chump2877
11-28-2006, 02:36 AM
it is an actual directory

you can;t include an entire directory in a PHP file.

the format is:


include 'file.php';or


include '/path/file.php';where "path" IS a directory.


Edit: Also post the code in your database connection script (the file represented by $connect in your code)
Edit: And another thing i just noticed, you are missing session_start() at the very top of your file, i.e.:

<?PHP
session_start();
include("$connect");


Edit: LOL, and....don;t use an upper case 'php'...don;t know if that's allowable...i.e.:

<?php
session_start();
include("$connect");

THM
11-28-2006, 02:40 AM
include("sql/connect2.php");



Thats what i have. As i said, It is correct there.. I use that code for all of them.
Its not that which is causing these.. "errors". I'm not sure what it is, its JUST this table that does this. Maybe I should redo the table?

chump2877
11-28-2006, 03:06 AM
See my "Edits" in my previous post...

THM
11-28-2006, 03:11 AM
All my PHPs are capitalized in my scripts, which work.
The connect thing, i've never used.

But, I did try it. Still, no luck. It just keeps loading and loading forever and ever. lol.

Any more ideas? Thanks for your help so far.

CFMaBiSmAd
11-28-2006, 04:43 AM
The while loop is a "forever" loop. The following line will just keep executing the query. As long as the query does not return a false, the while loop will keep looping... forever... (or until the web server/php script reaches its maximum time limit) -

while ($r = mysql_query($sql))After you form the query string, you need to execute the query once, with error checking and reporting, then fetch results in your while loop -

$result = mysql_query($sql) or die('Query failed: ' . mysql_error());
while ($r = mysql_fetch_assoc($result))
{
...
}Getting PHP to tell you all the errors when debugging will help. Put the following line in after your first opening PHP tag -

error_reporting(E_ALL);

CFMaBiSmAd
11-28-2006, 04:53 AM
i just don't want to post it on here because.. well, i've heard you should give as little as you can, by replacing with variables and such.By all means, xxxxxx out any sensitive information such as passwords/usernames... and your domain if you don't want that to be made public, but don't edit anything that would modify the intent and function of the actual code when you post it. Doing so just creates wild goose chases by people trying to solve apparent problems that are not really present.

THM
11-29-2006, 03:00 AM
Thank you guys SOOO much. Its working now. You're help was greatly appreciated.

Well, thanks to you my PM system will be up and running shortly. THANK YOU AGAIN!

:D

Heres, my last question in this topic :



<?php
include('XXXXX");

$sql = "SELECT * FROM `XXXXX_pm` WHERE touser = 'Johnn' ORDER BY 'date' ASC LIMIT 0 , 30";

$result = mysql_query($sql) or die('Query failed: ' . mysql_error());
while ($r = mysql_fetch_assoc($result))

{
$id = $r['id'];
$from = $r['fromuser'];
$subject = $r['subject'];
$date = $r['date'];
$msg = $r['message'];

}

$rowC = ($rowC=='row1' ? 'row2' : 'row1');
echo("<table width='470' cellpadding='0' cellspacing='0' class='PM'>");
echo("<tr class='header'><td>FROM</td><td>SUBJECT</td><td>DATE</td></tr> ");
echo("<tr class='$rowC'>");
echo("<td>$from</td>");
echo("<td>$subject</td>");
echo("<td>$date</td>");
echo("</tr>");
echo("</table>");
echo("<br />");
?>


How would I make it repeat the table foreach of the tables?

chump2877
11-29-2006, 04:57 AM
I think you just want to include your HTML table code inside the while loop:


<?php
include('XXXXX");

$sql = "SELECT * FROM `XXXXX_pm` WHERE touser = 'Johnn' ORDER BY 'date' ASC LIMIT 0 , 30";

$result = mysql_query($sql) or die('Query failed: ' . mysql_error());
while ($r = mysql_fetch_assoc($result))

{
$id = $r['id'];
$from = $r['fromuser'];
$subject = $r['subject'];
$date = $r['date'];
$msg = $r['message'];

$rowC = ($rowC=='row1' ? 'row2' : 'row1');
echo("<table width='470' cellpadding='0' cellspacing='0' class='PM'>");
echo("<tr class='header'><td>FROM</td><td>SUBJECT</td><td>DATE</td></tr> ");
echo("<tr class='$rowC'>");
echo("<td>$from</td>");
echo("<td>$subject</td>");
echo("<td>$date</td>");
echo("</tr>");
echo("</table>");
echo("<br />");
}
?>

THM
11-29-2006, 05:09 AM
Yupperrs!

Sure did work. THANKS!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum