Printing Values from MySQL
Hey guys, another PHP blunder of mine...
I am accessing a DB (MySQL), and i search for the values i need. i then want to print them into the corressponding places on the website. i have a file named index.php that has for example:
<p>Monday: $may29morn1</p>
and at the top of my page i have
<?php
include (\"/php/maysched.php\");
?>
and then in the included file i have this:
<?php
$connect= mysql_connect (\"localhost\", \"...\", \"...\") or die ('Database failure: ' . mysql_error($dbh));
mysql_select_db (\"...\");
$get=mysql_query(\"SELECT * FROM may SET\"
.\" may29morn1='$may29morn1'\"
.\",may29morn2='$may29morn2'\"
.\",may29morn3='$may29morn3'\"
.\",may29morn4='$may29morn4'\"
.\",may29aft1='$may29aft1'\"
.\",may29aft2='$may29aft2'\"
.\",may29aft3='$may29aft3'\"
.\",may29aft4='$may29aft4'\"
.\",may29des='$may29des'\"
.\",may29mid='$may29mid'\"
.\",may30morn1='$may30morn1'\"
.\",may30morn2='$may30morn2'\"
.\",may30morn3='$may30morn3'\"
.\",may30morn4='$may30morn4'\"
.\",may30aft1='$may30aft1'\"
.\",may30aft2='$may30aft2'\"
.\",may30aft3='$may30aft3'\"
.\",may30aft4='$may30aft4'\"
.\",may30des='$may30des'\"
.\",may30mid='$may30mid'\"
.\",may31morn1='$may31morn1'\"
.\",may31morn2='$may31morn2'\"
.\",may31morn3='$may31morn3'\"
.\",may31morn4='$may31morn4'\"
.\",may31aft1='$may31aft1'\"
.\",may31aft2='$may31aft2'\"
.\",may31aft3='$may31aft3'\"
.\",may31aft4='$may31aft4'\"
.\",may31des='$may31des'\"
.\",may31mid='$may31mid'\");
if ('time_since($dbh)=+3600'){
mysql_close($connect);
};
?>
get what i'm trying to do? btw...the if statement at the end is supposed to say, after a minute (in milliseconds) it closes the connection...just to make sure things get taken out of the db if the person is on a slow connection. but, as you may have guessed, it doesn't work. it connects and such, but doesn't display any of the info in the page.
any help is appreciated. lol, like always. thanks.
nike_guy_man posted this at 02:23 — 7th September 2003.
They have: 840 posts
Joined: Sep 2000
Well for one thing you aren't executing the $get, so that's why
Just do it like this:
<?php
PHP
$connect= mysql_connect (\"localhost\", \"...\", \"...\") or die ('Database failure: ' . mysql_error($dbh));
mysql_select_db (\"...\");
$get=mysql_query(\"SELECT * FROM may SET \");
if ($get) {
$info = mysql_fetch_assoc($get);
mysql_close;
} else {
echo \"error \" . mysql_error();
}
**other page**
include('otherpage.php');
echo \"$info[table field]\";
?>
That's how I do it....
nike_guy_man posted this at 02:24 — 7th September 2003.
They have: 840 posts
Joined: Sep 2000
Sigh... i'm an idiot
Move the mysql_close(); to the end of the loop
kb posted this at 15:18 — 7th September 2003.
He has: 1,380 posts
Joined: Feb 2002
ok i've got a question...what do you mean by "table field"? when run the script saying "table field" (even though i know thats not what it should say), I get an error that says I should look for the proper syntax near "SET" and "table field". thanks
nike_guy_man posted this at 15:52 — 7th September 2003.
They have: 840 posts
Joined: Sep 2000
Idiot mistake #2: remove "SET"
Table field is the name of the table field... in tihs case, $info[may29morn1]
kb posted this at 01:47 — 9th September 2003.
He has: 1,380 posts
Joined: Feb 2002
lol...i'd have to say it still doesn't work.
i removed "set" and i changed all the "table fields" to the corressponding values. i have tried two ways:
#1- just having the file name .php and the only php inside it is the includes and echo (so, its
<?php
include...echo
?>
#2- having
<?php
start after the body tag, the code (includes and echos), then having a print ('<table....');
?>
neither works. i also tried adding $ to the echo statement in front of the table field ($info[$may29morn1])...i'm not getting any error statements either...argh gagagagagah (Popeye quote...lol)
nike_guy_man posted this at 23:31 — 9th September 2003.
They have: 840 posts
Joined: Sep 2000
This is direct from one of my pages
<?php
## Connection info ##
$query = \"SELECT * FROM users \";
$result = mysql_query($query);
if ($result) {
$row = mysql_fetch_assoc($result);
} else {
echo \"Error \" . mysql_error();
}
echo \"$row[name]\";
mysql_close();
?>
I have no idea where I came up with the variables query result and row... i've been doing it that way for 3 years now...
A link and a .phps file would be nice so we could see what you are doing... put the dbase connection info on another page and include it so we don't see that....
kb posted this at 02:10 — 10th September 2003.
He has: 1,380 posts
Joined: Feb 2002
http://guards.dscpool.com is the basic idea, not the finalized design, but the basic idea/premise
the php file that is includes-ed is as follows:
<?php
$connect= mysql_connect (\"localhost\", \"...\", \"...\") or die ('Database failure: ' . mysql_error($dbh));
mysql_select_db (\"...\");
$get=mysql_query(\"SELECT * FROM may\");
if ($get) {
$info=mysql_fetch_assoc($get);
}
else {
echo \"Error:\" . mysql_error();
}
mysql_close($connect);
?>
nike_guy_man posted this at 02:58 — 10th September 2003.
They have: 840 posts
Joined: Sep 2000
Uhm... you know you have to open a PHP tag before it'll print that instead of $may29morn1 right?
It has to be either
<?php
echo $may29morn1;
?>
or the much easier
<?=$may29morn1 ?>
<?= means open, then echo, right?
Mark Hensler posted this at 08:01 — 10th September 2003.
He has: 4,048 posts
Joined: Aug 2000
Ya, that's one of the ideas they stole from ASP.
kb posted this at 00:29 — 11th September 2003.
He has: 1,380 posts
Joined: Feb 2002
no i didn't...lol
i thought since i included the $ tags inside the print(' ') (which i had the whole table inside) that it would automatically interpret, since i didn't use the "amperstand" symbol for the dollar sign ($).
thanks for dealing with me. lol.
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.