Hi All

Please can somebody help me. I am trying to output more than 1 row of data querying a table called tblbanners. The normal while loop isnt outputting more than 1 row. it seems to be just printing only 1 row. not too sure why? would be greatfull if somebody could help me please. each row outputted from the table should be outputted to a html table for each tr tag within the html table tag will be dynamic.

<?php 
		

		
		// identify the page name
		$page_class = split ("/", $_SERVER["REQUEST_URI"]); 
		$page =  $page_class[2];
		//echo $page;

		// check page name against either lnk column in tblmenu and tblsubmenu
		
		// 1st check the tblmenu lnk column
		
		$q = "SELECT Id,lnk FROM tblmenu WHERE lnk LIKE '$page'"; // query column original is $page
		$r = mysql_query($q,$con);
		$num_rows = mysql_num_rows($r);
		
				if ($num_rows = 0) // if there are no rows shown from the tblmenu then execute this script and change the $q variable to search the tblsubmenu
		
					{
					
						$q = "SELECT Id,lnk FROM tblsubmenu WHERE lnk LIKE '$page'";
						//echo "no value";
					
					}
					
					
					
					
				//$num_rows = myssql_num_rows($r);		There will only be 1 row hence no while loop				
				$row = mysql_fetch_array($r);
		
				$menuid = $row['Id']; // convert array into variables
				//echo $menuid.' ROWS';
					
		
		
			 // now we have the id value and file name we need to get the data from the tblbanners table and extract info into html table below
		   
		   
		   
		   $q2 = "SELECT txt,pic,alnk,lnkfile,height from tblbanner WHERE lnk_tblmenuid = $menuid AND banner_position = 'left' ORDER BY ord ASC";
		   $r2 = mysql_query($q2,$con);
		   $num_row2 = mysql_num_rows($r2);
		   
		   //echo $num_row2;
		   
		   		
				
					   while($row2 = mysql_fetch_assoc($r2))
					   
							{
							
							
											$r2 = $row2['txt'];
											$r3 = $row2['pic'];
											$r4 = $row2['alnk'];
											$r5 = $row2['lnkfile'];
											$r6 = $row2['height'];				
									
											echo 'DESCRIPTION: '.$r2.'PICTURE: '.$r3.'ALINK: '.$r4.'LINK FILE: '.$r5.'HEIGHT: '.$r6."<br>";
										
							}
						
		   ?>
           
            <div id="leftbanner"> <!--  ---------------------------- DIV for the left banner ------>
            
			  <table>
					<tr>
						<td height="200"> left Banner </td>
					</tr>
					<tr>
						<td height="300"> left Banner 2</td>
					</tr>
                    <tr>
						<td height="200"> left Banner 3</td>
					</tr>
			  </table>
            
            </div> <!--  ---------------------------- CLOSE DIV for the left banner ---------------->
            
            
            
			<div id="rightbanner">  <!--  ---------------------------- DIV for the right banner ------>
            
			  <table>
					<tr>
						<td height="200"> Right Banner </td>
					</tr>
					<tr>
						<td height="300"> Right Banner 2</td>
					</tr>
                    <tr>
						<td height="200"> Right Banner 3</td>
					</tr>
				</table>
            
            </div> <!--  ---------------------------- END DIV for the right banner ------>

Recommended Answers

All 2 Replies

Just windering if you got this problem fixed... If not. I'll check it. Although at first glance, I do see a problem with the code at the statement if ($num_rows = 0) This should be if ($num_rows == 0) You will have to use a double == to compare rather than a single = to assign.

If you are still facing a problem, I'll go into it deeper.

hi, im having probems with searching more than 1 table for the same thing. the script at the top, searches the page name on table tblmenu, how can i get it to search tblsubmenu if nothing is found searching tblmenu?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.