SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Nov 2004
    Location
    sydney
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    unsure, quick problem

    Hi everyone
    I am new to php, so im having trouble coding what i want to do. here is my code for my basic search engine. The user enters via a form the type of cuisine and the suburb.

    <?
    $username="kimbedso";
    $password="";
    $database="kimbedso_mydb";
    $cusine=$_POST['cusine'];
    $suburb=$_POST['suburb'];

    mysql_connect(localhost,$username,$password);
    @mysql_select_db($database) or die( "Unable to select database");
    $query="SELECT * FROM better WHERE cuisine='$cusine' and suburb='$suburb' ";
    $result=mysql_query($query);

    $num=mysql_numrows($result);

    mysql_close();

    echo "<b><center>Database Output</center></b><br><br>";

    $i=0;
    while ($i < $num) {

    $name=mysql_result($result,$i,"name");
    $sub=mysql_result($result,$i,"suburb");
    $cu=mysql_result($result,$i,"cuisine");
    $des=mysql_result($result,$i,"description");


    ?>

    <table width="564" border="0" cellpadding="0" cellspacing="0">
    <tr>
    <td width="392" height="25" valign="top" bgcolor="#99CCFF"><font face="Verdana, Arial, Helvetica, sans-serif"><b><? echo $name ?></b></font></td>
    <td width="172" valign="top" bgcolor="#99CCFF">
    <div align="right"><font face="Verdana, Arial, Helvetica, sans-serif"><? echo $sub ?></font></div>
    </td>
    </tr>
    <tr bgcolor="#CCFFFF">
    <td colspan="2" height="173" valign="top"><font face="Verdana, Arial, Helvetica, sans-serif"><? echo $des ?></font></td>
    </tr>
    </table>

    <?
    $i++;
    }

    ?>

    I think this script is fine, however i wish to add a checkbox, that when ticked will tell the script to search for the neighbouring suburbs as well. To do this I have created another column in my table called "suburb id" I have given each suburb a unique number, and to find the neighbouring suburbs you just add +1 +2 +3 -1 -2 -3 to the suburb id.

    So ill describe what i want the script to do

    If: checkbox isnt ticked then basically execute the code written above

    elseif: get the "suburb" value posted from the users form. Get this suburbs "suburb id" and display all the results for this suburb. add 1 to this id, and then display the results for this neighbouring suburb. then -1 from the id and display values. then +2, -2 up to 3.

    Can anyone give me pointers on how to write the code for this?

  2. #2
    SitePoint Wizard mark_W's Avatar
    Join Date
    Mar 2004
    Location
    West Midlands, United Kingdom
    Posts
    2,631
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If the check box is called suburb! imaginative I know! lol!

    the....

    PHP Code:
     
    if(isset($_POST['suburb'])) {
     
    // do your stuff for the suburbs
     
    } else {
     
    // do your code above
     



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •