Page 1 of 1

if statement

Posted: Wed Jul 30, 2003 9:33 am
by jamrop
Hey, I am trying to do an if statement which is working, the problem i am having is that if there is results, then they are displayed in my web page, but if there are no results, i get a message saying no results found, BUT it is displayed on a blank web page. I am trying to get it to display within my web page.

The code

Code: Select all

<?php


require('db.php');

$sql= "select advert.member_id,  advert.date, advert.type ,  advert.title, advert.description, advert.condition, advert.price,members.member_id,       
members.contact , members.location,
members.email, members.home_tel, members.mobile_tel
from advert, members
where advert.member_id=members.member_id
and type='$type' order by advert.date ";
$rs=mysql_query($sql,$db)or die("Select Failed");
$rowCheck = mysql_num_rows($rs);
if($rowCheck != 0){

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">



<html><!-- InstanceBegin template="/Templates/content.dwt" codeOutsideHTMLIsLocked="false" -->



<head>
<!-- InstanceBeginEditable name="doctitle" -->
<title>Main menu</title>
<!-- InstanceEndEditable --> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">



<script language="JavaScript" type="text/JavaScript">



<!--



function MM_preloadImages() { //v3.0



  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();



    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)



    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}



}







function MM_swapImgRestore() { //v3.0



  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;



}







function MM_findObj(n, d) { //v4.01



  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {



    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}



  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];



  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);



  if(!x && d.getElementById) x=d.getElementById(n); return x;



}







function MM_swapImage() { //v3.0



  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)



   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}



}



//-->



</script>
<!-- InstanceBeginEditable name="head" -->
<link href="../../style.css" rel="stylesheet" type="text/css">
<!-- InstanceEndEditable -->
</head>







<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onLoad="MM_preloadImages('../../classfied/home_f2.gif', '../../classfied/login_f2.gif', '../../classfied/reg_f2.gif', '../../classfied/help_f2.gif', '../../classfied/contact_f2.gif', '../../classfied/subhomebut_r1_c2_f2.gif', '../../classfied/subgardenbut_r1_c2_f2.gif', '../../classfied/subfamilybut_r1_c2_f2.gif', '../../classfied/subvehbut_r1_c2_f2.gif', '../../classfied/substudentbut_r1_c2_f2.gif')">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <!-- InstanceBeginEditable name="flash" -->
  <tr> 
    <td height="90" valign="top"><img src="../../classfied/huddlogo.gif" width="300" height="80"></td>
    <td align="right" valign="bottom"> <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="400" height="75">
        <param name="movie" value="../../classfied/advert.swf">
        <param name="quality" value="high">
        <embed src="../../classfied/advert.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="400" height="75"></embed></object></td>
  </tr>
  <tr bordercolor="#000000"> 
    <td width="45%" height="19" align="right" bgcolor="#000099"><font color="#FFFFFF" size="-1" face="Verdana, Arial, Helvetica, sans-serif"><strong>Bringing 
      People Together</strong></font></td>
    <td width="55%" align="left" valign="middle" bgcolor="#000099">&nbsp; </td>
  </tr>
  <!-- InstanceEndEditable -->
</table>



<table width="100%" border="1" cellpadding="0" cellspacing="0" bordercolor="#FFFFFF">
  <tr  bgcolor="#99CCFF"> 
    <td width="16%" height="29" align="center" valign="middle"><a href="../../hudds.htm" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('home', '', '../../classfied/home_f2.gif',1)"><img src="../../classfied/home.gif" name="home" width="105" height="25" border="0"></a></td>
    <td width="16%" align="center"><a href="../../login/login.php" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('login', '', '../../classfied/login_f2.gif',1)"><img src="../../classfied/login.gif" name="login" width="105" height="25" border="0"></a></td>
    <td width="16%" align="center"><a href="../../reg/register.php" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('reg', '', '../../classfied/reg_f2.gif',1)"><img src="../../classfied/reg.gif" name="reg" width="105" height="25" border="0"></a></td>
    <td width="16%" align="center"><a href="#" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('help', '', '../../classfied/help_f2.gif',1)"><img src="../../classfied/help.gif" name="help" width="105" height="25" border="0"></a></td>
    <td width="16%" align="center"><a href="#" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('contact', '', '../../classfied/contact_f2.gif',1)"><img src="../../classfied/contact.gif" name="contact" width="105" height="25" border="0"></a></td>
  </tr>
</table>



<table width="100%" border="0" cellpadding="0" cellspacing="0">



  <tr bgcolor="#000099"> 



    <td width="50%" height="29" align="right" valign="middle"></td>



    <td width="50%" valign="top"></td>



  </tr>



</table>



<table width="100%" height="418" border="0">



  <tr> 



    <td width="1%">



    <td width="98%" valign="top"> <table width="100%" border="0" cellpadding="0" cellspacing="1" bordercolor="#666666">
        <tr> <!-- InstanceBeginEditable name="cat" -->
          <td width="17%" height="282" align="center" valign="top" bgcolor="#FFFFFF"><font size="-1" face="Verdana, Arial, Helvetica, sans-serif"><strong>Catergory 
            </strong> </font> <table width="100%" border="1" cellpadding="1" cellspacing="1" bordercolor="#33CC99">
              <tr> 
                <td bgcolor="#99FFCC"><a href="forhome.php" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image10', '', '../../classfied/subhomebut_r1_c2_f2.gif',1)"><img name="Image10" border="0" src="../../classfied/subhomebut_r1_c2.gif"></a></td>
              </tr>
              <tr> 
                <td bgcolor="#99FFCC"><a href="#" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image9', '', '../../classfied/subgardenbut_r1_c2_f2.gif',1)"><img name="Image9" border="0" src="../../classfied/subgardenbut_r1_c2.gif"></a></td>
              </tr>
              <tr> 
                <td height="21" bgcolor="#99FFCC"><a href="#" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image11', '', '../../classfied/subfamilybut_r1_c2_f2.gif',1)"><img src="../../classfied/subfamilybut_r1_c2.gif" name="Image11" width="110" height="18" border="0"></a></td>
              </tr>
              <tr> 
                <td bgcolor="#99FFCC"><a href="#" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image13', '', '../../classfied/substudentbut_r1_c2_f2.gif',1)"><img src="../../classfied/substudentbut_r1_c2.gif" name="Image13" width="124" height="18" border="0"></a></td>
              </tr>
              <tr> 
                <td height="20" bgcolor="#99FFCC"><a href="#" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image12', '', '../../classfied/subvehbut_r1_c2_f2.gif',1)"><img name="Image12" border="0" src="../../classfied/subvehbut_r1_c2.gif"></a></td>
              </tr>
            </table>
            <font size="-1" face="Georgia, Times New Roman, Times, serif"><strong><br>
            Search</strong></font> <table width="100%" border="1" cellpadding="1" cellspacing="1" bordercolor="#33CC99">
              <form name="find" action="file:///D|/Web%20Sites/search.php" method="post">
                <tr> 
                  <td align="center" bgcolor="#99FFCC"> <input type="text" size="20" name="find"> 
                  </td>
                </tr>
                <tr> 
                  <td align="center" bgcolor="#99FFCC"><input name="submit" type="submit" value="Submit" size="20"></td>
                </tr>
              </form>
            </table><!-- InstanceEndEditable -->
          <td width="4%" valign="top"></td>
          <!-- InstanceBeginEditable name="main frame" --> 
         <?php while ($r=mysql_fetch_array($rs))

{
	$date = strtotime($r["date"]);
	$date = date("F js y", $date );
	$title = $r['title'];
	$desc = $r['description'];
	$cond = $r['condition'];
	$price = $r['price'];
	$contact = $r['contact'];
	$location = $r['location'];
	$email = $r['email'];
	$home_tel = $r['home_tel'];
	$mobile_tel=$r['movile_tel'];
	
	?>
		  <td width="79%" valign="top"><p><b><?php echo $type ?></b>&nbsp;</p>
            <p><?php echo ("$title $contact") ?>&nbsp;</p>
            <p>&nbsp;</p></td>
			<?php }
	}
	else {
	$errmsg = "Sorry, There are no adverts for this section";}  echo $errmsg ?>
          <!-- InstanceEndEditable --></tr>
      </table></tr>



</table>



</body>



<!-- InstanceEnd --></html>




?>

Any ideas

Thanks in advance

...

Posted: Wed Jul 30, 2003 1:15 pm
by kettle_drum
To make things easier with sites you can just split up your html template for the page and store them as 2 seperate files. Then in each page you want to show do something like:

<?php

include('top.php');
if(blah){
echo "this";
}else{
echo "this";
}
include('bottom.php');

?>

This then also makes it easier for you to change the design of your site without having to change loads of different files.

Posted: Wed Jul 30, 2003 3:15 pm
by m3rajk
it's happening because the entire webpage is in the first part of the if statement.

if all your pages start the same, make that a function in an include file and call that function to create the page