Display category

jblayney
jblayney used Ask the Experts™
on
Hello Again,
I am tring to show a list of products that fall under a certain category, their is a drop down list which sends the catID, the page that receives is supposed to catch the id number and display all the products wifth that id, this is what sends the info.....

 $option_block .="<option value='$catID'>$catName</option>";

} //end while

$display_block = "
<form method='post' action='showCategory.php'>
<select name='id'>
<option>Choose a Industry</option>
   $option_block  
  </select>
 <input type='submit' name='submit' value='Go'>
</form>";
?>

<? echo "$display_block"; ?>

and this is supposed to recive it , I am getting a blank page return

$sql = "SELECT * FROM $table_name WHERE catID = '$_REQUEST[id]' AND active = '1' ORDER BY busName ";

$result = @mysql_query($sql, $connection) or die("Error3 - ".mysql_error());

while($row = mysql_fetch_array($result)) {

$busID = $row['busID'];
    $catID = $row['catID'];
    $busName = $row['busName'];
    $busOwner = $row['busOwner'];
    $busAd = $row['busAd'];
    $busCity = $row['busCity'];
    $busPostal = $row['busPostal'];
    $busPhone = $row['busPhone'];
    $busPhone2 = $row['busPhone2'];
    $busFax = $row['busFax'];
    $busUrl = $row['busUrl'];
    $busEmail = $row['busEmail'];
    $busLogo = $row['busLogo'];
     $featured = $row['featured'];
        $keyWords = $row['keyWords'];
     $busDesc = $row['busDesc'];
     $active = $row['active'];


 $contact_list .= "<tr><td width='150'><img src='admin2/images/$busLogo'></td>";
 $contact_list .= "<td colspan='2'><font face='arial, helvetica' size='2'><b>$busName</b><br><b>tel: </b>$busTel<br>";
 $contact_list .= if($busUrl != "") { "<b>web : </b><a href='http://www.$busUrl'>$busUrl</a><br>"};
 $contact_list .= "<b>Email :</b>$busEmail<br></font></td>";
 $contact_list .= "<a href='businessDetails.php?id=".($row["busID"])'>More Info.....</a></font></td></tr>";

 } // end while


Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Author

Commented:
or even a link to a good tutorial

Commented:
Few clarifying questions...

Are you certain that the "id" is getting passed along?  Can you change it to a get, to see it in the query string, or just echo it on the listing page?
Are you certain you getting a result from the table?  Try echoing a mysql_num_rows($result) to see how many results it sees.
On the note of the last question... are you certain there is data in your DB that matches both requirements?  Has a catID of X and active is 1??

Never hurts to verify the simple stuff first.  With a quick glance, the code looks correct.. given the above are all ok.

Commented:
Few clarifying questions...

Are you certain that the "id" is getting passed along?  Can you change it to a get, to see it in the query string, or just echo it on the listing page?
Are you certain you getting a result from the table?  Try echoing a mysql_num_rows($result) to see how many results it sees.
On the note of the last question... are you certain there is data in your DB that matches both requirements?  Has a catID of X and active is 1??

Never hurts to verify the simple stuff first.  With a quick glance, the code looks correct.. given the above are all ok.
CompTIA Security+

Learn the essential functions of CompTIA Security+, which establishes the core knowledge required of any cybersecurity role and leads professionals into intermediate-level cybersecurity jobs.

Commented:
sorry for the double post, stupid computer...

on a side note, you could save yourself some code by doing the following:

$contact_list .= "<b>Email :</b>$row['busEmail']<br></font></td>";

No need to redefine the array elements as strings.  Just call the array inside your HTML code.  Saves some time coding, and also some clock cycles :)

Author

Commented:
thanks, ok, its my while loop more specifically the contact_list, my echo sql tests worked and returned everthing I asked for, I changed the code a bit, this is it
The echos work if I hide the rest under it.

while($row = mysql_fetch_array($result)) {


$busID = $row['busID'];
    $catID = $row['catID'];
    $busName = $row['busName'];
    $busOwner = $row['busOwner'];
    $busAd = $row['busAd'];
    $busCity = $row['busCity'];
    $busPostal = $row['busPostal'];
    $busPhone = $row['busPhone'];
    $busPhone2 = $row['busPhone2'];
    $busFax = $row['busFax'];
    $busUrl = $row['busUrl'];
    $busEmail = $row['busEmail'];
    $busLogo = $row['busLogo'];
     $featured = $row['featured'];
        $keyWords = $row['keyWords'];
     $busDesc = $row['busDesc'];
     $active = $row['active'];
echo "sql : $sql<BR>";
echo "sql : $active<BR>";
 $contact_list .= "<tr><td width='150'><img src='admin2/images/$busLogo'></td></tr>";
 $contact_list .= "<td colspan='2'><font face='arial, helvetica' size='2'><b>$busName</b><br><b>tel: </b>$busTel<br>";
 $contact_list .= if($busUrl != "") { "<b>web : </b><a href='http://www.$busUrl'>$busUrl</a><br>"};
 $contact_list .= "<b>Email :</b>$busEmail<br></font></td>";
 $contact_list .= "<a href='businessDetails.php?id=".$row["busID"]"'>More Info.....</a></font></td></tr>";

 }  end while

Commented:
Guess I'm still not understanding the problem.

I presuming that you actually do echo $contact_list at a later point, since I don't see it in the above code.

One problem I see is that after your email line, you close your table cell "</td>" but then in the next line you put some more HTML code and then close your td/tr.  You probably want to remove the td at the end of the email line.

If that doesn't get what you are looking for, you could try commenting out different lines and find out which line allows it to work, then you know where to look for the problem.

But the above td problem, will definately remedy any table issues you may be having.

If I'm still off base, please provide what IS being printed, and what SHOULD be printed.

Author

Commented:
The problem is that if I have any part of contact_list  in the code , I return a totally blank page, I have tried to  hide each individual line in contact_list, but all give me the same result, If I take it out completely, my echo sql tests work perfect. This is the code in its entirery

<?

$db_name = "xxxxxxxxxx";

$table_name = "business";

$connection = @mysql_connect("xxxxxxxxx", "xxxxxxxxx", "xxxxxxxxxxx") or die("Error1 - ".mysql_error());

$db = @mysql_select_db($db_name, $connection) or die("Error2 - ".mysql_error());

$sql = "SELECT * FROM $table_name WHERE catID = '$_REQUEST[id]' AND active = '1' ORDER BY busName ";

$result = @mysql_query($sql, $connection) or die("Error3 - ".mysql_error());

while($row = mysql_fetch_array($result)) {


$busID = $row['busID'];
    $catID = $row['catID'];
    $busName = $row['busName'];
    $busOwner = $row['busOwner'];
    $busAd = $row['busAd'];
    $busCity = $row['busCity'];
    $busPostal = $row['busPostal'];
    $busPhone = $row['busPhone'];
    $busPhone2 = $row['busPhone2'];
    $busFax = $row['busFax'];
    $busUrl = $row['busUrl'];
    $busEmail = $row['busEmail'];
    $busLogo = $row['busLogo'];
     $featured = $row['featured'];
        $keyWords = $row['keyWords'];
     $busDesc = $row['busDesc'];
     $active = $row['active'];
echo "sql : $sql<BR>";
echo "sql : $active<BR>";
 $contact_list .= "<tr><td width='150'><img src='admin2/images/$busLogo'></td>";
 $contact_list .= "<td colspan='2'><font face='arial, helvetica' size='2'><b>$busName</b></td><td><b>tel: </b>$busTel<br>";
 $contact_list .= if($busUrl != "") { "<b>web : </b><a href='http://www.$busUrl'>$busUrl</a><br>"};
 $contact_list .= "<b>Email :</b>$busEmail<br></font></td>";
 $contact_list .= "<td><a href='businessDetails.php?id=".$row["busID"]"'>More Info.....</a></font></td></tr>";

 }  end while


?>
 <? include ("headerTop.php"); ?>
 <? include ("buttons.php"); ?>
<table width="100%" height="381" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="150" valign="top">
      <? include ("sideButtons.php"); ?>
    </td>
    <td height="381" align="left" valign="top">
      <table width="100%" height="373" border="0" cellpadding="5" cellspacing="5">
        <tr>
          <td height="363" valign="top">
            <table width="100%" cellspacing="2" border="0" cellpadding="2>
             <?  echo "$contact_list" ?>
             </table>
             
            </td>
        </tr>
      </table></td>
    <td width="150" height="381" valign="top">
<? include ("advertisments.php"); ?></td>
  </tr>
</table>
<table width="100%" height="70" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td><? include ("footer.php"); ?></td>
  </tr>
</table>
</body>
</html>

Commented:
I don't see anything wrong with the PHP.  You are missing your closing quote on the cellpadding right before your echo $contact_list call... that MIGHT have something to do with it.

If you view the source of the page is it blank as well?  If not can you provide the code that is there.

Author

Commented:
When I view the source code, the results are completely blank, their is no output at all.
Commented:
ok, I'm an idiot...

The major problem is that you can't do an IF statement inside of a string, reverse it... do the if statement, and if it's true THEN set the string.

Referring to:
$contact_list .= if($busUrl != "") { "<b>web : </b><a href='http://www.$busUrl'>$busUrl</a><br>"};

should be

if($busUrl != "") { $contact_list .= "<b>web : </b><a href='http://www.$busUrln'>$busUrl</a><br>";}

Minor issue is:
$contact_list .= "<td><a href='businessDetails.php?id=".$row["busID"]"'>More Info.....</a></font></td></tr>";

should be

$contact_list .= "<td><a href='businessDetails.php?id=".$row['busID']."'>More Info.....</a></font></td></tr>";

The array should use ' instead of " around busID.  Also you needed the "." to go back into the string AFTER the array call.

Author

Commented:

OK, I fixed the problem, I rewrote the code step by step really slowly and now it works, that the first stage, what I need now is for when their is more than 5  entries  new pages will be created, along with page numbers for the amount of pages created which be links, like google does when they have lots of returns, I have no idea how to do this, could someone help please. this is the code as it is now.
while($row = mysql_fetch_array($result)) {
   $busID = $row['busID'];
   $catID = $row['catID'];
   $busName = $row['busName'];
    $busEmail = $row['busEmail'];
    $busLogo = $row['busLogo'];
    $busPhone = $row['busPhone'];
    $busUrl = $row['busUrl'];     
$contact_list .= "<tr><td width='150' align='center' rowspan='2'>";
if($busLogo != "") { $contact_list .= "<img src='admin2/images/$busLogo'>";}
$contact_list .= "</td>";
$contact_list .= "<td colspan='2' valign='top'><b>$busName</b></td></tr><tr>";
$contact_list .= "<td valign='top'><b>Email: </b><a href='mailto:$busEmail' class='buttons'>$busEmail</a><br><b>Tel: </b> $busPhone<br></td><td valign='top'>";
if($busUrl != "") { $contact_list .= "<b>Website : </b><a href='http://www.$busUrl' class='buttons'>$busUrl</a> <br>";}
$contact_list .= "<a href='businessDetails.php?id=$busID' class='buttons'>More Details.....</a></td></tr>";
$contact_list .= "<tr><td colspan='3'><hr width='75%' color='#cccccc'></td></tr>";
} // end while

Commented:
pagination is a whole other ball of wax... you'll want to make that a separate question

Author

Commented:
I dont know where to strt, where can i find an easy tutorial

Commented:
Just out of curiosity, this is the 2nd B you've given me when I've answered your questions fine... what do you define as "A" work?

Author

Commented:
I don't know, its no offence, but I consider myself a newbie, and my questions are not that hard (maybe I'm wrong), But for this question, the answer you gave me didn't help ( i used it in the code ), but I didn't get it going until I rewrote the code a line at a time, testing it as I went, I would have given you an A for a pagination answer which was really what I wanted with this thread, even before  I started it. I do really appreciate your help. I honestly didn't know how seriously the grades were meant to be. In the future I will know. Please tell me your thougts on this.

Commented:
A question is a question.. if you consider it hard or not, is where you assign it 10 vs 500 points for an answer.

The grade given is how well a person answered your given question. This is totally independant of how hard you thought the question was, you already assiged the difficulty in the points.

You say that "the answer you gave me didn't help", but you used all my suggestions in your final solution. I pointed out your TD problem, if statement problem, and concatenation problem (missing the ".")... all of which were used in your final code.  So without those suggestions, your code would STILL not work, and so they DID help.

As for giving an "A" for the pagination answer... that would have been above and beyond your original question, and in all fairness, should have been worth EXTRA points, not as a reason to give a full grade.

I am not offended either... just pondering your logic, and explaining the process.

Author

Commented:
I apologize,
point well taken.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial