Page 1 of 2

multiple while with mysql link.

Posted: Wed Aug 05, 2009 10:11 am
by synking
Hey i am trying to create a page that builds a 3 column table from a mysql database.

the way i have it setup is that all the mysql connection and query is done with in one page and then i have it process to include the actual page that outputs what is seen. so i have i query that pulls the info from mysql then it runs a few if statements if the result is incorrect or it is empty it out puts the search form. and if it gets info it outputs the table. At this point i want to be able to have a filter option for the mysql query so the table can be filtered. i am doing this be creating an select option in the table head with a while statement.


Code: Select all

while ($row = mysql_fetch_array($result))
{
    echo ("<option value=/"$row['city']/">$row[city]</option>\n");
}

I have this under the city column in the table. THe problem is that it only process this statement and seems to quit. It will not process the table or any of the other information after that bit of code.

Re: multiple while with mysql link.

Posted: Wed Aug 05, 2009 1:28 pm
by William
Look at the source code of the page, there is a chance that there is a PHP error in the select box and it's screwing with your HTML. For instance, your $row[city] will throw a E_NOTICE since it's not a constant.

Re: multiple while with mysql link.

Posted: Wed Aug 05, 2009 2:02 pm
by dzynit
Are you sure it's not simply a typing error? $row['city']/">$row[city] the second $row[city] doesn't have the ' marks.

Re: multiple while with mysql link.

Posted: Wed Aug 05, 2009 2:16 pm
by William
dzynit wrote:Are you sure it's not simply a typing error? $row['city']/">$row[city] the second $row[city] doesn't have the ' marks.
I don't doubt that there isn't a constant "city", I was just pointing out that PHP will think it's a constant, thus throwing a E_NOTICE which could break his HTML rendering.

Re: multiple while with mysql link.

Posted: Wed Aug 05, 2009 2:39 pm
by aceconcepts
Does your option list populate?

Try using mysql_error() to show errors if they exist.

Re: multiple while with mysql link.

Posted: Wed Aug 05, 2009 3:01 pm
by synking
Yes what happens is that the one option list populates and nothing else. and the typing error here is just here. The code is actually processed through an error checking that i have create the actual script in the page is

Code: Select all

<?PHP
                  while ($row = $connector->fetchArray($result)) {
                         echo ("<option value=\"$row['city']\">$row['city']</option>\n";)
             }?>
where the connector actual does do mysql error checking and the process the request. I am hoping it is not a mysql error. I don't get any errors it just will stop processing any php after this block of code

Re: multiple while with mysql link.

Posted: Wed Aug 05, 2009 3:09 pm
by William
synking wrote:Yes what happens is that the one option list populates and nothing else. and the typing error here is just here. The code is actually processed through an error checking that i have create the actual script in the page is

Code: Select all

<?PHP
                  while ($row = $connector->fetchArray($result)) {
                         echo ("<option value=\"$row['city']\">$row['city']</option>\n";)
             }?>
where the connector actual does do mysql error checking and the process the request. I am hoping it is not a mysql error. I don't get any errors it just will stop processing any php after this block of code
Is

Code: Select all

 
</option>\n";)
 
another typo?

Re: multiple while with mysql link.

Posted: Wed Aug 05, 2009 3:16 pm
by synking
yes sorry thought i had it printed perfectly i am sorry. the thing is i never get any error it prints the start of the table gets to the option field creation it prints nothing else.

this is the source from the output of the page.

Code: Select all

<html>
 <head>
   <title>Result of Access Number search</title>
    <style type="text/css" media="screen">
      @import "css.php";
    </style>
 </head>
 <body>
 <table id="dbresult">
   <thead>
 
    <tr>
     <th>City</th>
     <th>State</th>
     <th>Access Number</th>
     <th>Carrier</th>
    </tr>
    <tr>
 
     <th><form id="filter_city" action="access_check.php" onSubmit="return valid(this)" method="get" name="filter_city">
          Select State:  
     <select name="filter_city" id="filter_select" size="1">
               <option value="Bethany">Bethany</option>
<option value="Bethany">Bethany</option>
<option value="Bethel">Bethel</option>
<option value="Bethel">Bethel</option>
<option value="Bethel">Bethel</option>
<option value="Cincinnati">Cincinnati</option>
 
<option value="Cincinnati">Cincinnati</option>
<option value="Cincinnati">Cincinnati</option>
<option value="Cincinnati">Cincinnati</option>
<option value="Cincinnati">Cincinnati</option>
<option value="Cincinnati">Cincinnati</option>
<option value="Cincinnati">Cincinnati</option>
<option value="Cincinnati">Cincinnati</option>
<option value="Cincinnati">Cincinnati</option>
<option value="Clermont">Clermont</option>
 
<option value="Clermont">Clermont</option>
<option value="Clermont">Clermont</option>
<option value="Clermont">Clermont</option>
<option value="Hamilton">Hamilton</option>
<option value="Hamilton">Hamilton</option>
<option value="Hamilton">Hamilton</option>
<option value="Hamilton">Hamilton</option>
<option value="Hamilton">Hamilton</option>
<option value="Hamilton">Hamilton</option>
 
<option value="Hamilton">Hamilton</option>
<option value="Hamilton">Hamilton</option>
<option value="Harrison">Harrison</option>
<option value="Harrison">Harrison</option>
<option value="Harrison">Harrison</option>
<option value="Lebanon">Lebanon</option>
<option value="Lebanon (warren)">Lebanon (warren)</option>
<option value="Lebanon (warren)">Lebanon (warren)</option>
<option value="Lebanon (warren)">Lebanon (warren)</option>
 
<option value="Little Miami">Little Miami</option>
<option value="Little Miami">Little Miami</option>
<option value="Little Miami">Little Miami</option>
<option value="Little Miami">Little Miami</option>
<option value="Little Miami">Little Miami</option>
<option value="Little Miami">Little Miami</option>
<option value="Little Miami">Little Miami</option>
<option value="Mason">Mason</option>
<option value="Mason">Mason</option>
 
<option value="Mason">Mason</option>
<option value="Mason">Mason</option>
<option value="Middletown">Middletown</option>
<option value="Middletown">Middletown</option>
<option value="Middletown">Middletown</option>
<option value="Middletown">Middletown</option>
<option value="Middletown">Middletown</option>
<option value="Middletown">Middletown</option>
<option value="Middletown">Middletown</option>
 
<option value="Middletown">Middletown</option>
<option value="Monroe">Monroe</option>
<option value="Newtonsville">Newtonsville</option>
<option value="Newtonsville">Newtonsville</option>
<option value="Newtonsville">Newtonsville</option>
<option value="Oxford">Oxford</option>
<option value="Oxford">Oxford</option>
<option value="Oxford">Oxford</option>
<option value="Oxford">Oxford</option>
 
<option value="Oxford">Oxford</option>
<option value="Oxford">Oxford</option>
<option value="Seven Mile">Seven Mile</option>
<option value="Seven Mile">Seven Mile</option>
<option value="Seven Mile">Seven Mile</option>
<option value="South Lebanon">South Lebanon</option>
<option value="South Lebanon">South Lebanon</option>
<option value="South Lebanon">South Lebanon</option>
<option value="South Lebanon">South Lebanon</option>
 
<option value="South Lebanon">South Lebanon</option>
<option value="South Lebanon">South Lebanon</option>
<option value="Trenton">Trenton</option>
<option value="Williamsburg">Williamsburg</option>
<option value="Williamsburg">Williamsburg</option>
<option value="Williamsburg">Williamsburg</option>
     </th>
    </tr>
    
   </thead>
 
   <tbody>
  </tbody>
 </table>
</body>
</html>
 
 
it never prints anything in the table but does print the option select box.

Re: multiple while with mysql link.

Posted: Wed Aug 05, 2009 3:19 pm
by William
synking wrote:yes sorry thought i had it printed perfectly i am sorry. the thing is i never get any error it prints the start of the table gets to the option field creation it prints nothing else.

this is the source from the output of the page.

Code: Select all

<html>
 <head>
   <title>Result of Access Number search</title>
    <style type="text/css" media="screen">
      @import "css.php";
    </style>
 </head>
 <body>
 <table id="dbresult">
   <thead>
 
    <tr>
     <th>City</th>
     <th>State</th>
     <th>Access Number</th>
     <th>Carrier</th>
    </tr>
    <tr>
 
     <th><form id="filter_city" action="access_check.php" onSubmit="return valid(this)" method="get" name="filter_city">
          Select State:  
     <select name="filter_city" id="filter_select" size="1">
               <option value="Bethany">Bethany</option>
<option value="Bethany">Bethany</option>
<option value="Bethel">Bethel</option>
<option value="Bethel">Bethel</option>
<option value="Bethel">Bethel</option>
<option value="Cincinnati">Cincinnati</option>
 
<option value="Cincinnati">Cincinnati</option>
<option value="Cincinnati">Cincinnati</option>
<option value="Cincinnati">Cincinnati</option>
<option value="Cincinnati">Cincinnati</option>
<option value="Cincinnati">Cincinnati</option>
<option value="Cincinnati">Cincinnati</option>
<option value="Cincinnati">Cincinnati</option>
<option value="Cincinnati">Cincinnati</option>
<option value="Clermont">Clermont</option>
 
<option value="Clermont">Clermont</option>
<option value="Clermont">Clermont</option>
<option value="Clermont">Clermont</option>
<option value="Hamilton">Hamilton</option>
<option value="Hamilton">Hamilton</option>
<option value="Hamilton">Hamilton</option>
<option value="Hamilton">Hamilton</option>
<option value="Hamilton">Hamilton</option>
<option value="Hamilton">Hamilton</option>
 
<option value="Hamilton">Hamilton</option>
<option value="Hamilton">Hamilton</option>
<option value="Harrison">Harrison</option>
<option value="Harrison">Harrison</option>
<option value="Harrison">Harrison</option>
<option value="Lebanon">Lebanon</option>
<option value="Lebanon (warren)">Lebanon (warren)</option>
<option value="Lebanon (warren)">Lebanon (warren)</option>
<option value="Lebanon (warren)">Lebanon (warren)</option>
 
<option value="Little Miami">Little Miami</option>
<option value="Little Miami">Little Miami</option>
<option value="Little Miami">Little Miami</option>
<option value="Little Miami">Little Miami</option>
<option value="Little Miami">Little Miami</option>
<option value="Little Miami">Little Miami</option>
<option value="Little Miami">Little Miami</option>
<option value="Mason">Mason</option>
<option value="Mason">Mason</option>
 
<option value="Mason">Mason</option>
<option value="Mason">Mason</option>
<option value="Middletown">Middletown</option>
<option value="Middletown">Middletown</option>
<option value="Middletown">Middletown</option>
<option value="Middletown">Middletown</option>
<option value="Middletown">Middletown</option>
<option value="Middletown">Middletown</option>
<option value="Middletown">Middletown</option>
 
<option value="Middletown">Middletown</option>
<option value="Monroe">Monroe</option>
<option value="Newtonsville">Newtonsville</option>
<option value="Newtonsville">Newtonsville</option>
<option value="Newtonsville">Newtonsville</option>
<option value="Oxford">Oxford</option>
<option value="Oxford">Oxford</option>
<option value="Oxford">Oxford</option>
<option value="Oxford">Oxford</option>
 
<option value="Oxford">Oxford</option>
<option value="Oxford">Oxford</option>
<option value="Seven Mile">Seven Mile</option>
<option value="Seven Mile">Seven Mile</option>
<option value="Seven Mile">Seven Mile</option>
<option value="South Lebanon">South Lebanon</option>
<option value="South Lebanon">South Lebanon</option>
<option value="South Lebanon">South Lebanon</option>
<option value="South Lebanon">South Lebanon</option>
 
<option value="South Lebanon">South Lebanon</option>
<option value="South Lebanon">South Lebanon</option>
<option value="Trenton">Trenton</option>
<option value="Williamsburg">Williamsburg</option>
<option value="Williamsburg">Williamsburg</option>
<option value="Williamsburg">Williamsburg</option>
     </th>
    </tr>
    
   </thead>
 
   <tbody>
  </tbody>
 </table>
</body>
</html>
 
 
it never prints anything in the table but does print the option select box.
It looks like your problem is the code that is supposed to fill in the contents between <tbody></tbody> not your option box.

Re: multiple while with mysql link.

Posted: Wed Aug 05, 2009 3:36 pm
by synking
well what i have there is a simple while statment.

Code: Select all

<?php
   while ($row = mysql_fetch_array($result)) {
     echo ('
    <tr>
     <td>'.$row["city"].'</td>
     <td>'.$row["state"].'</td>
     <td>'.$row["npa"].'-'.$row["nxx"].'-'.$row["localnum"].'</td>
     <td>'.$row["carrier"].'</td>
    </tr>');
   }?>
 
so unless i am missing something there it has no problems and even if i comment out the select option series it will process the table info.

Re: multiple while with mysql link.

Posted: Wed Aug 05, 2009 4:18 pm
by aceconcepts
It sounds like you have an unclosed tag or syntax errors.

Re: multiple while with mysql link.

Posted: Wed Aug 05, 2009 4:22 pm
by synking
here is the entire page that does the processing.

Code: Select all

<?php
$stateOptions = '';
$cityOptions = '';
while ($row = mysql_fetch_array($result))
{
    $stateOptions .= "<option value=\"{$row['state']}\">{$row['state']}</option>\n";
    $cityOptions .= "<option value=\"{$row['city']}\">{$row['city']}</option>\n";
}
?>
<html>
 <head>
   <title>Result of Access Number search</title>
    <style type="text/css" media="screen">
      @import "css.php";
    </style>
 </head>
 <body>
 <table id="dbresult">
   <thead>
    <tr>
     <th>City</th>
     <th>State</th>
     <th>Access Number</th>
     <th>Carrier</th>
    </tr>
    <tr>
     <th><form id="filter_city" action="access_check.php" onSubmit="return valid(this)" method="get" name="filter_city">
          Select State:
     <select name="filter_city" id="filter_select" size="1">
               <?PHP
                   echo ($cityOptions);
             ?>
     </th>
     <th>
    </tr>
   </thead>
   <tbody>
<?php
   while ($row = $connector->fetchArray($result)) {
     echo ('
    <tr>
     <td>'.$row["city"].'</td>
     <td>'.$row["state"].'</td>
     <td>'.$row["npa"].'-'.$row["nxx"].'-'.$row["localnum"].'</td>
     <td>'.$row["carrier"].'</td>
    </tr>');
   }?>
  </tbody>
 </table>
</body>
</html>
I have been trying to tweak it but it still does not seem to work.

Re: multiple while with mysql link.

Posted: Wed Aug 05, 2009 4:38 pm
by aceconcepts
From line 32 you haven't closed your form or select element.

Re: multiple while with mysql link.

Posted: Thu Aug 06, 2009 8:27 am
by synking
Ok i found out what the problem was i was not resetting my result from the MYSql query so it was working but there was no information to pull as the first while left off at the end of the mysql table. So i just had to reset the result. thanks guys.

Re: multiple while with mysql link.

Posted: Thu Aug 06, 2009 8:44 am
by straightman
why are u using the forward slashes to scape the quotes when it should be backslashes?


Alvaro


============================================================================================

synking wrote:Hey i am trying to create a page that builds a 3 column table from a mysql database.

the way i have it setup is that all the mysql connection and query is done with in one page and then i have it process to include the actual page that outputs what is seen. so i have i query that pulls the info from mysql then it runs a few if statements if the result is incorrect or it is empty it out puts the search form. and if it gets info it outputs the table. At this point i want to be able to have a filter option for the mysql query so the table can be filtered. i am doing this be creating an select option in the table head with a while statement.


Code: Select all

while ($row = mysql_fetch_array($result))
{
    echo ("<option value=/"$row['city']/">$row[city]</option>\n");
}

I have this under the city column in the table. THe problem is that it only process this statement and seems to quit. It will not process the table or any of the other information after that bit of code.