Page 1 of 1

php dynamic links

Posted: Wed Nov 16, 2011 9:08 am
by eugbana
hi, please i would really love it if someone can help me on this....
i have a project am working on that is similar to the famous booking.com, after a search is made and a list a hotels and locations are displayed... my dynamic link is done here.. but because of the mysql_fetch_array() function, the link is applied to all the other data from my db..


this is what i want to achieve
.. i have a db called hotel and its populated with state in the us.. eg newyork, california etc..
if one searches for usa, all the state in usa is been displayed.. so to narrow down the search he clicks on one of the states and it displays all the hotels in that state and when u click on another state it displays hotels related to the particular state...


Question
How do i go about achieving this and do i need to create separate tables for each state, if that be the case how do i link each of them dynamically..

Awaiting an answer ASAP
thanks

Re: php dynamic links

Posted: Wed Nov 16, 2011 9:13 am
by Celauran
eugbana wrote:because of the mysql_fetch_array() function, the link is applied to all the other data from my db..
What does this mean? Do you have any sample code?

eugbana wrote:this is what i want to achieve
.. i have a table called usa and usa is populated with state in the us.. eg newyork, california etc..
if one searches for usa, all the state in usa is been displayed.. so to narrow down the search he clicks on one of the states and it displays all the hotels in that state and when u click on another state it displays hotels related to the particular state...


Question
How do i go about achieving this and do i need to create separate tables for each state, if that be the case how do i link each of them dynamically..
You could use GET (ie. display.php?state=CA) or you could do it through AJAX if you don't want a page refresh.

Re: php dynamic links

Posted: Wed Nov 16, 2011 10:23 am
by eugbana
thanks for the reply guys ..
here is the code

Code: Select all

<?php require_once(''); ?>
<?php $search = $_GET['searchstr']; ?>

<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$maxRows_search = 10;
$pageNum_search = 0;
if (isset($_GET['pageNum_search'])) {
  $pageNum_search = $_GET['pageNum_search'];
}
$startRow_search = $pageNum_search * $maxRows_search;

$colname_search = "-1";
if (isset($_GET['searchstr'])) {
  $colname_search = $_GET['searchstr'];
}
mysql_select_db($database_conn, $conn);
$query_search = sprintf("SELECT * FROM location WHERE state like %s or area like %s or count like %s or image like %s", GetSQLValueString("%" . $colname_search . "%", "text"),GetSQLValueString("%" . $colname_search . "%", "text"),GetSQLValueString("%" . $colname_search . "%", "text"),GetSQLValueString("%" . $colname_search . "%", "text"));
$query_limit_search = sprintf("%s LIMIT %d, %d", $query_search, $startRow_search, $maxRows_search);
$search = mysql_query($query_limit_search, $conn) or die(mysql_error());
$row_search = mysql_fetch_assoc($search);

if (isset($_GET['totalRows_search'])) {
  $totalRows_search = $_GET['totalRows_search'];
} else {
  $all_search = mysql_query($query_search);
  $totalRows_search = mysql_num_rows($all_search);
}
$totalPages_search = ceil($totalRows_search/$maxRows_search)-1;

mysql_select_db($database_conn, $conn);
$query_maitama = "SELECT * FROM maitama";
$maitama = mysql_query($query_maitama, $conn) or die(mysql_error());
$row_maitama = mysql_fetch_assoc($maitama);
$totalRows_maitama = mysql_num_rows($maitama);

?>

<?php $searched = $_GET['searchstr']; ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>bookink4walls.com</title>

<link href="css/style.css" rel="stylesheet" type="text/css" />
 





</head>
<body>

<table width="100%" height="110" border="0" align="center" cellpadding="0">
  <tr align="left">
    <td valign="top"><table width="1161" border="0" align="center" cellpadding="0">
      <tr>
        <td width="1157" valign="top" bgcolor="#FFFFFF"><div id="body2">
          <div id="login2"><table width="100%" border="0" cellspacing="2">
  <tr>
    <td width="16%" height="73" valign="top"><a href="index.php"><img src="images/logo.png" width="140" height="33" border="0" /></a></td>
    <td width="9%" valign="middle"><div id="checking" class="menu"><a href="index.html">check booking</a></div></td>
    <td width="18%" valign="middle"><div id="credit"><a href="#" class="menu">get book4walls credit</a></div></td>
    <td width="17%" valign="middle"><div id="flight"><a href="#">book a flight</a></div></td>
    <td width="17%" valign="middle"><div id="affiliate"><a href="#">affiliated website</a></div></td>
    <td width="23%" valign="middle"><div id="contact"><a href="#">contact us</a></div></td>
  </tr>
</table>
          </div>
          <div id="logo"></div>
          <div id="space"></div>
          <div id="content2">
          <table width="100%" border="0" cellspacing="3">
            
              <tr>
                <td height="17" colspan="4" valign="top"><?php echo"$totalRows_search result found in your search for $searched"; ?><br />Please click the destination you would like to go to?<hr color="#990000" /></td>
                </tr>
              <?php if ($totalRows_search == 0) { echo "No result found" ?>
                <tr>
                  <td height="46" colspan="4" valign="top"></td>
                </tr>
                <?php } // Show if recordset empty ?>
<?php do { ?>
                <tr>
                  <td width="11%"><img src="<?php echo $row_search['image']; ?>" alt="" width="121" height="121" border="0" /></td>
                  <td width="42%" valign="top"><?php echo $row_search['state']; ?><br />
                    <a href="detailed_result.php?maitama=<?php echo $row_maitama['location']; ?>"><?php echo $row_search['area']; ?></a><br /></td>
                  <td width="0%" valign="top">&nbsp;</td>
                  <td width="47%" valign="top"><?php echo $row_search['count']; ?></td>
                </tr>
                <?php } while ($row_search = mysql_fetch_assoc($search)); ?>
          </table>

          </div>
          <div id="footer">Content for  id "footer" Goes Here</div>
        </div></td>
      </tr>
    </table></td>
  </tr>
</table>
</body>
</html>
<?php
mysql_free_result($search);

mysql_free_result($maitama);

?>

Re: php dynamic links

Posted: Wed Nov 16, 2011 10:34 am
by Celauran
[ syntax=php] code goes here [/syntax]
Thanks.

Re: php dynamic links

Posted: Wed Nov 16, 2011 11:31 am
by eugbana
you know what will send you the link so you have an idea of what i want to do

Re: php dynamic links

Posted: Thu Nov 17, 2011 3:42 am
by eugbana
ratioplusafrica.com/hotel

type in abuja in the search field and run a search, click on any of the links, you will notice that it displays the same thing, which isnt what i want

Re: php dynamic links

Posted: Fri Nov 18, 2011 3:34 am
by eugbana
is there no one to help me on this

Re: php dynamic links

Posted: Mon Nov 28, 2011 3:41 am
by eugbana
hmmm... this is suppose to be a forum right, if one has a problem it is brought here and people try to see hw they can help,
but no one rendered any help to me though.. well if y'all must knw, i was able to crack it up myself.. thanks for nothing

Re: php dynamic links

Posted: Mon Nov 28, 2011 3:44 am
by mikeashfield
Make sure to come back again when you hit a brick wall.