displaying result from a listbox on the same page from mysql
Posted: Fri Dec 17, 2004 2:18 am
ok i know i'm a newbie
here's my database in mysql
table name:jokes
fileds id(primary key),JokeText(text),JokeDate(Date)
i want to display the result dynamically from the listbox when a user selects the jokes,so it diplays all the info about that joke.
my problem is that i don't anything displaying from the database at first only when the user selects something
Here is the code i started working on,,pls help me anyone..
gratefull,,,,thks
nevx
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
</HEAD>
<BODY>
<FORM ACTION="<?php echo($PHP_SELF); ?>" METHOD=POST>
<?php
$username = "";
$password = "";
$hostname = "localhost";
$dbh = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
print "Connected to MySQL<br>";
$selected = mysql_select_db("jokes",$dbh)
or die("Could not select Jokes");
$query = "SELECT JokeText FROM jokes";
$result = mysql_query($query);
print "<SELECT name=joketext>";
while ($line = mysql_fetch_array($result))
{
foreach ($line as $value)
{
print "<OPTION value='$value'";
}
print ">$value</OPTION>";
}
mysql_close($selected);
print "</SELECT><p>";
?>
<BR><br><INPUT TYPE=SUBMIT NAME="submitsel" VALUE="FIND">
</form>
<?
if ("SUBMIT" == $submitsel)
{
$sql = "select JokeText from jokes where JokeText='$value'";
if (mysql_query($sql))
{
echo("<P>Your joke has been added.</P>");
}
else
{
echo("<P>Error adding submitted joke: " .
mysql_error() . "</P>"); } } echo("<P> Here are all the jokes in our database: </P>");
// Request the text of all the jokes
$result = mysql_query("select * from jokes where JokeText='$joketext'");
if (!$result)
{
echo("<P>Error performing query: " .
mysql_error() . "</P>");
exit();
}
// Display the text of each joke in a paragraph
while ( $row = mysql_fetch_array($result) )
{
print "ID:".$row{'id'}." Joke: ".$row{'JokeText'}." "."Date:<b> " . $row{'JokeDate'}."</b><br>";
}
?>
</BODY>
</HTML>
here's my database in mysql
table name:jokes
fileds id(primary key),JokeText(text),JokeDate(Date)
i want to display the result dynamically from the listbox when a user selects the jokes,so it diplays all the info about that joke.
my problem is that i don't anything displaying from the database at first only when the user selects something
Here is the code i started working on,,pls help me anyone..
gratefull,,,,thks
nevx
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
</HEAD>
<BODY>
<FORM ACTION="<?php echo($PHP_SELF); ?>" METHOD=POST>
<?php
$username = "";
$password = "";
$hostname = "localhost";
$dbh = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
print "Connected to MySQL<br>";
$selected = mysql_select_db("jokes",$dbh)
or die("Could not select Jokes");
$query = "SELECT JokeText FROM jokes";
$result = mysql_query($query);
print "<SELECT name=joketext>";
while ($line = mysql_fetch_array($result))
{
foreach ($line as $value)
{
print "<OPTION value='$value'";
}
print ">$value</OPTION>";
}
mysql_close($selected);
print "</SELECT><p>";
?>
<BR><br><INPUT TYPE=SUBMIT NAME="submitsel" VALUE="FIND">
</form>
<?
if ("SUBMIT" == $submitsel)
{
$sql = "select JokeText from jokes where JokeText='$value'";
if (mysql_query($sql))
{
echo("<P>Your joke has been added.</P>");
}
else
{
echo("<P>Error adding submitted joke: " .
mysql_error() . "</P>"); } } echo("<P> Here are all the jokes in our database: </P>");
// Request the text of all the jokes
$result = mysql_query("select * from jokes where JokeText='$joketext'");
if (!$result)
{
echo("<P>Error performing query: " .
mysql_error() . "</P>");
exit();
}
// Display the text of each joke in a paragraph
while ( $row = mysql_fetch_array($result) )
{
print "ID:".$row{'id'}." Joke: ".$row{'JokeText'}." "."Date:<b> " . $row{'JokeDate'}."</b><br>";
}
?>
</BODY>
</HTML>