Oct 21st, 2005, 04:13 AM
#1
Thread Starter
Fanatic Member
load data from database to list menu
i'm try to load data from database to list menu...but dont know y cannot work.....anyone can point out my mistake?? i attach my file together.......
Attached Files
Last edited by kenny_oh; Nov 1st, 2005 at 10:16 AM .
Oct 21st, 2005, 05:03 AM
#2
Re: load data from database to list menu
Code:
while ($x < $numrows){
$program = mysql_result($results, $x, "programTitle");
echo "<option>$program</option>\n"
$x++;
}
}
You have two closing curly brackets, you shoul only have one.
Oct 21st, 2005, 06:35 AM
#3
Thread Starter
Fanatic Member
Re: load data from database to list menu
that bracket is for the top side if statement!
Oct 21st, 2005, 08:22 AM
#4
Lively Member
Re: load data from database to list menu
It's mysql_num_rows() and you have mysql_NumRows()
But it seems as if you're putting more work into it than you need, why not just loop through each record and print out your field, instead of calling mysql_result() each time through?
PHP Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Enter Program Schedule</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.style1 {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
}
.style2 {color: #FF9933}
.style5 {color: #000000}
.style6 {
font-family: Arial, Helvetica, sans-serif;
font-size: 14px;
}
.style7 {color: #FF0000}
-->
</style>
</head>
<body>
<?php
$host = "localhost" ;
$dbname = "Broadcast" ;
$dbpass = "" ;
$connection = mysql_connect ( " $host " , " $dbname " , " $dbpass " );
$db = mysql_select_db ( " $dbname " , $connection );
$results = mysql_query ( "select programTitle from tblProgram" , $connection ) or die( mysql_error ());
$numrows = mysql_num_rows ( $results );
if ( $numrows > 0 )
{
?>
<form>
<p align="center"> </p>
<p align="center"> </p>
<p align="center"> </p>
<p align="center"> </p>
<p align="center"> </p>
<p align="center"> </p>
<div align="center">
<table width="522" height="90" border="0">
<tr>
<td width="169" height="35"><div align="center" class="style1"><span class="style2">*</span>Program Title </div></td>
<td width="23"> </td>
<td width="316"><div align="left">
<input name="txtProgTitle" type="text" id="txtProgTitle" size="40">
<select name="selectTitle" id="selectTitle">
<?php
while ( $row = mysql_fetch_assoc ( $results ))
{
$program = $row [ 'programTitle' ];
echo "<option> $program </option>\n"
}
}
?>
</select>
</div></td>
</tr>
<tr>
<td width="169" height="35"><div align="center" class="style1"><span class="style2">*</span>Episode</div></td>
<td> </td>
<td><div align="left">
<input name="txtEpisode" type="text" id="txtEpisode">
</div></td>
</tr>
<tr>
<td width="169" height="35"><div align="center" class="style1"><span class="style2">*</span>Episode title </div></td>
<td> </td>
<td><div align="left">
<input name="txtEpisodeTitle" type="text" id="txtEpisodeTitle" size="30">
</div></td>
</tr>
</table>
<p> </p>
<table width="531" height="64" border="0">
<tr>
<td width="176" height="35"><div align="center" class="style1"><span class="style2">*</span>Date</div></td>
<td width="20"> </td>
<td width="321"><div align="left">
<select name="selectProgDay" id="selectProgDay">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>
<select name="selectProgMonth" id="selectProgMonth">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
</select>
<select name="selectProgYear" id="selectProgYear">
<option value="2005">2005</option>
<option value="2006">2006</option>
<option value="2007">2007</option>
<option value="2008">2008</option>
<option value="2009">2009</option>
<option value="2010">2010</option>
</select>
</div></td>
</tr>
<tr>
<td height="35"><div align="center" class="style1"><span class="style2">*</span>Time</div></td>
<td> </td>
<td><div align="left"><span class="style1"><span class="style2">*</span>Start</span>
<input name="txtStart" type="text" id="txtStart" size="10" maxlength="4">
<span class="style1"><span class="style2">*</span>End</span> <input name="txtEnd" type="text" id="txtEnd" size="10" maxlength="4">
<span class="style2"><span class="style5">(</span><span class="style5"><span class="style2">*</span>eg: 1845)</span> </span></div></td>
</tr>
</table>
<table width="529" border="0">
<tr>
<td width="171" height="87"><div align="center" class="style1"><span class="style2">*</span>Description</div></td>
<td width="21"> </td>
<td width="315" height="90">
<div align="left">
<textarea name="txtDescription" cols="35" rows="5" wrap="VIRTUAL" id="txtDescription"></textarea>
</div></td>
</tr>
</table>
<table width="528" height="28" border="00">
<tr>
<td width="167" height="40"> </td>
<td width="25"> </td>
<td width="109"><div align="left"><img src="btn_Enter.gif" width="100" height="18"></div></td>
<td width="199"><img src="cancel_btn.gif" width="100" height="18"></td>
</tr>
</table>
<p> </p>
<p> </p>
<table width="791" height="66" border="0" bgcolor="#FFFFFF">
<tr>
<td width="377"><div align="right"><img src="FIFA%202006.GIF" width="340" height="65"></div></td>
<td width="398"><img src="NHL.GIF" width="340" height="65"></td>
</tr>
</table>
<p><span class="style6">Kenny<span class="style7">Tv.com</span></span></p>
<p> </p>
</div>
<div align="center"> </div>
<p align="center"> </p>
</form>
</body>
</html>
Oct 21st, 2005, 08:34 AM
#5
Thread Starter
Fanatic Member
Re: load data from database to list menu
data didnt load into menu...and this line code display at the top of the form
0){ //$numrows = mysql_NumRows($results); //$x = 0; if ($numrows > 0){ ?>
Oct 21st, 2005, 09:05 AM
#6
Lively Member
Re: load data from database to list menu
Post the code you used, I don't see anywhere in the page I posted it has those lines...
Oct 21st, 2005, 09:09 AM
#7
Thread Starter
Fanatic Member
Re: load data from database to list menu
Attached Files
Oct 21st, 2005, 09:19 AM
#8
Lively Member
Re: load data from database to list menu
We forgot a semicolon here:
echo "<option>$program</option>\n";
Oct 21st, 2005, 09:25 AM
#9
Thread Starter
Fanatic Member
Re: load data from database to list menu
i change alr....but that line stil exists and menu still empty
Oct 21st, 2005, 09:28 AM
#10
Lively Member
Re: load data from database to list menu
echo out $numrows or test the query to make sure it returns some rows.
Oct 21st, 2005, 09:56 AM
#11
Thread Starter
Fanatic Member
Re: load data from database to list menu
nothing...js print out the word "echo '$numrows'
Oct 21st, 2005, 10:03 AM
#12
Lively Member
Re: load data from database to list menu
Do you have the page saved as .php?
Oct 21st, 2005, 10:06 AM
#13
Thread Starter
Fanatic Member
Re: load data from database to list menu
errr..this is htm woh...want save as .php?
Oct 21st, 2005, 10:09 AM
#14
Lively Member
Re: load data from database to list menu
Yes, the file extension needs to be .php, so somepage.php.
Oct 21st, 2005, 10:12 AM
#15
Thread Starter
Fanatic Member
Re: load data from database to list menu
oic...thank......i make this mistake...
Oct 21st, 2005, 05:11 PM
#16
Fanatic Member
Re: load data from database to list menu
Originally Posted by
{yak}
Yes, the file extension needs to be .php, so somepage.php.
Just want to clarify, it doesn't need to be this, its just the way the hoster has setup PHP. Most only allow the php extension. To make things simple for me, I enabled it for both html and php on my server.
But, to be on the safe side, always use xxx.php.
Oct 23rd, 2005, 02:40 AM
#17
PowerPoster
Re: load data from database to list menu
Originally Posted by
k1ll3rdr4g0n
Just want to clarify, it doesn't need to be this, its just the way the hoster has setup PHP. Most only allow the php extension. To make things simple for me, I enabled it for both html and php on my server.
But, to be on the safe side, always use xxx.php.
Not a good thing because it causes PHP to be loaded for HTML files that may not require PHP at all, I believe its recommended to just use .php unless you really need to.
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width