Jump to content

Basic PHP Help


phpbeginner

Recommended Posts

I have 3 tables (sectors, subsectors, and business). From the site a site user can select a sector, which then lists the subsectors, then when they select a sub sector they can view a list of the businesses within the selection.

 

I am trying to remove a step so that they will see the sectors and be able to select, then will list the subsectors with the business names under the subsectors.

 

The code I have is prior to removing the step is ......

 

<?php 
$rs=mysql_query("select * from tblmain WHERE id='$view'");                     
while($row=mysql_fetch_row($rs)){
foreach ($row as $k => $v){
$row[$k] = nl2br($v);
} 

echo("<h4>" . $row[1] . " Sectors </h4>");         
}
?>
        
        <ul>


          <?php 
$pnds=1;
if (isset($_GET["id"])) $pnds=$_GET["id"];
$sql = "select * from tblsub WHERE catid='$view' ORDER BY subsec ";
$reccount=$sq->numsrow($sql);
if ($reccount > 0) {
$ata =$sq->query($sql);
while($rs=$sq->fetch($ata))
{
?>	

<li><a href="listings.php?view=<?php echo $rs["subsec"];?>"><?php echo $rs["subsec"];?></a></li> 


<?php

} 
}
?>
</ul>

 

I have tried to get this to work but the problem I am having is $view is an number but the actual business table is not id, it is by subsector name.  I have tried .......

 

<?php 
$rs=mysql_query("select * from tblmain WHERE id='$view'");                     
while($row=mysql_fetch_row($rs)){
foreach ($row as $k => $v){
$row[$k] = nl2br($v);
} 

echo("<h4>" . $row[1] . " Sectors </h4>");         
}
?>
        
        <ul>


          <?php 
$pnds=1;
if (isset($_GET["id"])) $pnds=$_GET["id"];
$sql = "select * from tblsub WHERE catid='$view' ORDER BY subsec ";
$reccount=$sq->numsrow($sql);
if ($reccount > 0) {
$ata =$sq->query($sql);
while($rs=$sq->fetch($ata))
{
?>	

<li><a href="listings.php?view=<?php echo $rs["subsec"];?>"><?php echo $rs["subsec"];?></a></li> 
<?php 
$rs=mysql_query("select * from tblbusiness WHERE category='$view' ORDER BY name"); 
                    
while($row=mysql_fetch_row($rs)){
foreach ($row as $k => $v){
$row[$k] = nl2br($v);
}

print(" . $row[2] . ");

}

<?php

} 
}
?>
</ul>

 

But obviously category is by name and not $view which is an id.

 

Any help would be greatly appreciated.

Link to comment
https://forums.phpfreaks.com/topic/255672-basic-php-help/
Share on other sites

Latest effort........

 

<?php 
$rs=mysql_query("select name, category from tblbusiness ORDER BY name, tblsub WHERE subsec=category ");                    
while($row=mysql_fetch_row($rs)){
foreach ($row as $k => $v){
$row[$k] = nl2br($v);
}
echo("" . $row[name] . "");
}
?>

Link to comment
https://forums.phpfreaks.com/topic/255672-basic-php-help/#findComment-1310614
Share on other sites

I now have this much....it lists the subsectors but as you can see I just grabbed the info from tblbusiness WHERE category= 'Bed and Brekfast'  while I am trying to grab from tblbusiness WHERE category = from tblsub WHERE catid='$view'

 

          <?php 
$pnds=1;
if (isset($_GET["id"])) $pnds=$_GET["id"];
$sql = "select * from tblsub WHERE catid='$view' ORDER BY subsec ";
$reccount=$sq->numsrow($sql);
if ($reccount > 0) {
$ata =$sq->query($sql);
while($rs=$sq->fetch($ata))
{
?>	

<li><a href="listings.php?view=<?php echo $rs["subsec"];?>"><?php echo $rs["subsec"];?></a></li> 
<p>
<?php 
$rs=mysql_query("SELECT * FROM tblbusiness WHERE category = 'Bed and Breakfast'");                    
while($row=mysql_fetch_row($rs)){
foreach ($row as $k => $v){
$row[$k] = nl2br($v);
}
echo("" . $row[2] . "   |  ");
}
?>
</p>
<?php

} 
}
?>

Link to comment
https://forums.phpfreaks.com/topic/255672-basic-php-help/#findComment-1310646
Share on other sites

My latest attempt, to no avail.........

 

          <?php 
$pnds=1;
if (isset($_GET["id"])) $pnds=$_GET["id"];
$sql = "select * from tblsub WHERE catid='$view' ORDER BY subsec ";
$reccount=$sq->numsrow($sql);
if ($reccount > 0) {
$ata =$sq->query($sql);
while($rs=$sq->fetch($ata))
{
?>	

<li><a href="listings.php?view=<?php echo $rs["subsec"];?>"><?php echo $rs["subsec"];?></a></li> 
<p>
<?php 
$rs=mysql_query("SELECT tblbusiness.category, tblsub.subsec FROM tblbusiness JOIN tblsub WHERE tblbusiness.category = tblsub.subsec AND tblsub.catid='$view'");                    
while($row=mysql_fetch_row($rs)){
foreach ($row as $k => $v){
$row[$k] = nl2br($v);
}
echo("" . $row[2] . "   |  ");
}
?>
</p>
<?php

} 
}
?>
</ul>

Link to comment
https://forums.phpfreaks.com/topic/255672-basic-php-help/#findComment-1310667
Share on other sites

Here is something I just tried......the only thing is it lists all the subsector businesses under each subsector and did not sepearte them as per subsector.

 

          <?php 
$pnds=1;
if (isset($_GET["id"])) $pnds=$_GET["id"];
$sql = "select * from tblsub WHERE catid='$view' ORDER BY subsec ";
$reccount=$sq->numsrow($sql);
if ($reccount > 0) {
$ata =$sq->query($sql);
while($rs=$sq->fetch($ata))
{
?>	

<li><a href="listings.php?view=<?php echo $rs["subsec"];?>"><?php echo $rs["subsec"];?></a></li> 

<p>
<?php 
$rs=mysql_query("SELECT tblbusiness.*, tblsub.* FROM tblbusiness JOIN tblsub WHERE tblbusiness.category = tblsub.subsec AND tblsub.catid='$view'");                    
while($row=mysql_fetch_row($rs)){
foreach ($row as $k => $v){
$row[$k] = nl2br($v);
}
echo("" . $row[2] . "   |  ");
}
?>
</p>
<?php

} 
}
?>
</ul>

Link to comment
https://forums.phpfreaks.com/topic/255672-basic-php-help/#findComment-1310687
Share on other sites

My initial query works fine, displaying the results of subsectors.

 

$sql = "select * from tblsub WHERE catid='$view' ORDER BY subsec ";

 

However to list all the businesses under the correct subsector, I am using this....

 

$rs=mysql_query("SELECT tblbusiness.*, tblsub.* FROM tblbusiness JOIN tblsub WHERE tblbusiness.category = tblsub.subsec AND tblsub.catid='$view'");

 

As the common fld between the 2 tables is tblbusiness.category and tblsub.subsec

Link to comment
https://forums.phpfreaks.com/topic/255672-basic-php-help/#findComment-1310788
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.