View Full Version : PLEASE HELP.....ive been at this a long time
grudz
01-14-2004, 06:51 PM
I am have trouble with a simple task but cant figure out a way to solve the problem. I have a main page that lists my records. However, i also have other pages that query to that main page. Now i dont want to have to create a dozen other pages, i want everything to happen on that main page.
PHP:
SELECT name, address, smalldescription, type, location, icons, smallpic, blackline
FROM listing
WHERE type = 'coltype' OR address LIKE '%coladdress%'
ORDER BY name ASC
now the problem is when i add the OR.........the 'address' part might work, but the 'type' doesnt (it doesnt filter my information).......i dont know if u understand my problem. But what it boils down to is that i have numerous pages that when i click on a query (lets say, sort by name, or show me the records according to...... ) i want them ALL to go to my main page, i dont want to have to create a bunch of other pages
thank you in advance
Welcome here!
I don't quite understand the problem.
That the where clause doesn't work. Hmm. Yeah, but we can't say much about that. The syntax is correct but i have no clue what data is inside your table.
I suppose you do realise that if you use the OR operator, that only one of the conditions needs to evaluate true.
About your lulti-purpose page issue.
I'm not sure what help you expect. The basic setup is that all links should point to the same page, and that you append the sortorder and the variable to sort o, to the querystring.
For instance, you could have links like
<a href="./index.php?var=name&order=asc" title="...>
<a href="./index.php?var=name&order=desc" title="...>
<a href="./index.php?var=type&order=asc" title="...>
....
then inside indew.php, you build your query like
$select="SELECT name, address, smalldescription, type, location, icons, smallpic, blackline
FROM listing
WHERE type = 'coltype' OR address LIKE '%coladdress%'
ORDER BY " . $_GET['var'] . " ". $_GET['order']
So you dynamically build the sql-statement with the values from the querystring.
But maybe this isn't what you're looking for...
grudz
01-14-2004, 08:16 PM
www.mtl-baseline.com......click on lounge on the left......as u can see....the url becomes....http://www.mtl-baseline.com/list.php?type=lounge .....thats perfect ......
but the click on 'fontaine'....then on the bottom....click 'Go'.....see it goes back to list.php
..... but there is nothing.....its supposed to show me some info....if i create another .php page...it'll work.....but not if i link it back to list.php
thanx
but the click on 'fontaine'....then on the bottom....click 'Go'.....see it goes back to list.php..... but there is nothing.....its supposed to show me some info....if i create another .php page...it'll work.....but not if i link it back to list.php
I can't help you if you dont give more info then that.
The 'Go' button is a submitbutton of this form:
<form action="list.php" method="post" name="address" id="address">
<input name="address" type="text" class="textfield" id="address" value="Crescent street">
<input name="type" type="text" class="textfield" id="type" value="lounge">
<input type="submit" name="Submit" value="Go"></form>
So if you click itn the 'adress' and 'type' will be posted to list.php.
Posted means that they are in the formscollection and can be accessed like
$_POST['address']
$_POST['type']
If you want the form-variables to be in the querystringcollection, then you need to use
<form action="list.php" method="get" name="address" id="address">
You will then see them in the querystring in your adress-bar, and you can acces them with
$_GET['address']
$_GET['type']
grudz
01-15-2004, 05:21 PM
what kind of info do u want....?
For instnce, elaborate on
but there is nothing.....its supposed to show me some info....
What should be shown?
The first link you posted obviously doesn't work, so i have no idea what you expect to so. With the info you give, all we can say is 'There is something wrong'
You could also post some relevant code so that wa can see what kind of input you expect and what sort of output it should generate.
But there is nothing wrong with your sql-statement. it' s probably some PHP problem.
grudz
01-15-2004, 10:58 PM
ok...here's the code in the head of my page
<?php
$currentPage = $HTTP_SERVER_VARS["PHP_SELF"];
mysql_select_db($database_baseline, $baseline);
$query_Legend = "SELECT * FROM legend";
$Legend = mysql_query($query_Legend, $baseline) or die(mysql_error());
$row_Legend = mysql_fetch_assoc($Legend);
$totalRows_Legend = mysql_num_rows($Legend);
$maxRows_List = 2;
$pageNum_List = 0;
if (isset($HTTP_GET_VARS['pageNum_List'])) {
$pageNum_List = $HTTP_GET_VARS['pageNum_List'];
}
$startRow_List = $pageNum_List * $maxRows_List;
$colname_List = "1";
if (isset($HTTP_GET_VARS['type'])) {
$colname_List = (get_magic_quotes_gpc()) ? $HTTP_GET_VARS['type'] : addslashes($HTTP_GET_VARS['type']);
}
mysql_select_db($database_baseline, $baseline);
$query_List = sprintf("SELECT name, streetnumber, address, smalldescription, type, location, icons, smallpic, blackline FROM listing WHERE type = '%s' ORDER BY name ASC", $colname_List);
$query_limit_List = sprintf("%s LIMIT %d, %d", $query_List, $startRow_List, $maxRows_List);
$List = mysql_query($query_limit_List, $baseline) or die(mysql_error());
$row_List = mysql_fetch_assoc($List);
if (isset($HTTP_GET_VARS['totalRows_List'])) {
$totalRows_List = $HTTP_GET_VARS['totalRows_List'];
} else {
$all_List = mysql_query($query_List);
$totalRows_List = mysql_num_rows($all_List);
}
$totalPages_List = ceil($totalRows_List/$maxRows_List)-1;
mysql_select_db($database_baseline, $baseline);
$query_Endnotes = "SELECT * FROM endnotes";
$Endnotes = mysql_query($query_Endnotes, $baseline) or die(mysql_error());
$row_Endnotes = mysql_fetch_assoc($Endnotes);
$totalRows_Endnotes = mysql_num_rows($Endnotes);
mysql_select_db($database_baseline, $baseline);
$query_bar = "SELECT DISTINCT type FROM listing WHERE type = 'bar n pub'";
$bar = mysql_query($query_bar, $baseline) or die(mysql_error());
$row_bar = mysql_fetch_assoc($bar);
$totalRows_bar = mysql_num_rows($bar);
mysql_select_db($database_baseline, $baseline);
$query_resto = "SELECT type FROM listing WHERE type = 'resto'";
$resto = mysql_query($query_resto, $baseline) or die(mysql_error());
$row_resto = mysql_fetch_assoc($resto);
$totalRows_resto = mysql_num_rows($resto);
mysql_select_db($database_baseline, $baseline);
$query_cafe = "SELECT type FROM listing WHERE type = 'cafe'";
$cafe = mysql_query($query_cafe, $baseline) or die(mysql_error());
$row_cafe = mysql_fetch_assoc($cafe);
$totalRows_cafe = mysql_num_rows($cafe);
mysql_select_db($database_baseline, $baseline);
$query_lounge = "SELECT type FROM listing WHERE type = 'lounge'";
$lounge = mysql_query($query_lounge, $baseline) or die(mysql_error());
$row_lounge = mysql_fetch_assoc($lounge);
$totalRows_lounge = mysql_num_rows($lounge);
mysql_select_db($database_baseline, $baseline);
$query_club = "SELECT type FROM listing WHERE type = 'club'";
$club = mysql_query($query_club, $baseline) or die(mysql_error());
$row_club = mysql_fetch_assoc($club);
$totalRows_club = mysql_num_rows($club);
mysql_select_db($database_baseline, $baseline);
$query_Items = "SELECT * FROM `index items`";
$Items = mysql_query($query_Items, $baseline) or die(mysql_error());
$row_Items = mysql_fetch_assoc($Items);
$totalRows_Items = mysql_num_rows($Items);
$queryString_List = "";
if (!empty($HTTP_SERVER_VARS['QUERY_STRING'])) {
$params = explode("&", $HTTP_SERVER_VARS['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_List") == false &&
stristr($param, "totalRows_List") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_List = "&" . implode("&", $newParams);
}
}
$queryString_List = sprintf("&totalRows_List=%d%s", $totalRows_List, $queryString_List);
$MM_paramName = "";
$MM_paramName = "";
// *** Go To Record and Move To Record: create strings for maintaining URL and Form parameters
// create the list of parameters which should not be maintained
$MM_removeList = "&index=";
if ($MM_paramName != "") $MM_removeList .= "&".strtolower($MM_paramName)."=";
$MM_keepURL="";
$MM_keepForm="";
$MM_keepBoth="";
$MM_keepNone="";
// add the URL parameters to the MM_keepURL string
reset ($HTTP_GET_VARS);
while (list ($key, $val) = each ($HTTP_GET_VARS)) {
$nextItem = "&".strtolower($key)."=";
if (!stristr($MM_removeList, $nextItem)) {
$MM_keepURL .= "&".$key."=".urlencode($val);
}
}
// add the URL parameters to the MM_keepURL string
if(isset($HTTP_POST_VARS)){
reset ($HTTP_POST_VARS);
while (list ($key, $val) = each ($HTTP_POST_VARS)) {
$nextItem = "&".strtolower($key)."=";
if (!stristr($MM_removeList, $nextItem)) {
$MM_keepForm .= "&".$key."=".urlencode($val);
}
}
}
// create the Form + URL string and remove the intial '&' from each of the strings
$MM_keepBoth = $MM_keepURL."&".$MM_keepForm;
if (strlen($MM_keepBoth) > 0) $MM_keepBoth = substr($MM_keepBoth, 1);
if (strlen($MM_keepURL) > 0) $MM_keepURL = substr($MM_keepURL, 1);
if (strlen($MM_keepForm) > 0) $MM_keepForm = substr($MM_keepForm, 1);
// *** Go To Record and Move To Record: create strings for maintaining URL and Form parameters
// create the list of parameters which should not be maintained
$MM_removeList = "&index=";
if ($MM_paramName != "") $MM_removeList .= "&".strtolower($MM_paramName)."=";
$MM_keepURL="";
$MM_keepForm="";
$MM_keepBoth="";
$MM_keepNone="";
// add the URL parameters to the MM_keepURL string
reset ($HTTP_GET_VARS);
while (list ($key, $val) = each ($HTTP_GET_VARS)) {
$nextItem = "&".strtolower($key)."=";
if (!stristr($MM_removeList, $nextItem)) {
$MM_keepURL .= "&".$key."=".urlencode($val);
}
}
// add the URL parameters to the MM_keepURL string
if(isset($HTTP_POST_VARS)){
reset ($HTTP_POST_VARS);
while (list ($key, $val) = each ($HTTP_POST_VARS)) {
$nextItem = "&".strtolower($key)."=";
if (!stristr($MM_removeList, $nextItem)) {
$MM_keepForm .= "&".$key."=".urlencode($val);
}
}
}
and here's the table where it's all going be shown.....the list
<table width="610" border="0" cellpadding="0" cellspacing="0" class="normal">
<?php do { ?>
<tr>
<td width="2" height="48" align="left" valign="top"> </td>
<td width="100" align="center" valign="top"><a href="establishment.php?<?php echo $MM_keepNone.(($MM_keepNone!="")?"&":"")."name=".$row_List['name'] ?>"><?php echo $row_List['smallpic']; ?></a></td>
<td width="375" align="left" valign="top" nowrap><span class="link"><strong><a href="establishment.php?<?php echo $MM_keepNone.(($MM_keepNone!="")?"&":"")."name=".$row_List['name'] ?>" class="link"><?php echo $row_List['name']; ?></a></strong></span><strong><a href="establishment.php?<?php echo $MM_keepNone.(($MM_keepNone!="")?"&":"")."name=".$row_List['name'] ?>"><span class="typelink"> </span></a></strong><br>
<?php echo $row_List['streetnumber']; ?><?php echo $row_List['address']; ?><br>
<br>
<?php echo $row_List['smalldescription']; ?></td>
<td width="25" align="left" valign="top"><strong><a href="search_location.php?<?php echo $MM_keepNone.(($MM_keepNone!="")?"&":"")."location=".$row_List['location'] ?>" class="normal"><strong><?php echo $row_List['location']; ?></strong></a></td>
<td width="65" align="center" valign="top" nowrap><strong><?php echo $row_List['icons']; ?></strong></td>
</tr>
<tr>
<td colspan="5"><?php echo $row_List['blackline']; ?></td>
</tr>
<?php } while ($row_List = mysql_fetch_assoc($List)); ?>
</table>
tell me if u need more.....basically the problem is that i want one page to be like the 'search result' of 10 other pages.......the information has to be at the same place, just different types......
well, you have this to build the recordset that will be printed
if (isset($HTTP_GET_VARS['type'])) {
$colname_List = (get_magic_quotes_gpc()) ? $HTTP_GET_VARS['type'] : addslashes($HTTP_GET_VARS['type']);
}
mysql_select_db($database_baseline, $baseline);
$query_List = sprintf("SELECT name, streetnumber, address, smalldescription, type, location, icons, smallpic, blackline FROM listing WHERE type = '%s' ORDER BY name ASC", $colname_List);
$query_limit_List = sprintf("%s LIMIT %d, %d", $query_List, $startRow_List, $maxRows_List);
$List = mysql_query($query_limit_List, $baseline) or die(mysql_error());
$row_List = mysql_fetch_assoc($List);
The $HTTP_GET_VARS['type'] tells me that you need to use the "get " method inside the formtag.
Else no type wille be passed to the selectstatement.
I also don't understand why you don't have a loop while-statement in your code until at the very bottom. Makes no sense to me.
grudz
01-19-2004, 08:03 PM
First off, I am a PHP amateur, i use Dreamweaver, that generates all the code for me, i am in the prcess of learning as much php as i can.
Also, i dont think i explained myself correctly; let me try again.
this is my situation:
i have page A that lists my records depending on information from pages B, C, D, E, etc......however the WHERE clause from page A as to be something like this.
'Show me the records WHERE type = information from page page B'
'Show me the records WHERE type = information from page page C'
'Show me the records WHERE type = information from page page D'
'Show me the records WHERE type = information from page page E'
OR
'Show me the records WHERE name = information from page page B'
'Show me the records WHERE name = information from page page C'
'Show me the records WHERE name = information from page page D'
'Show me the records WHERE name = information from page page E'
So on page A, the 'type' and 'name' information is dependent on multiple pages, and those pages' information name is the same (address, name, location, etc....)
i understand and know the sql statements
SELECT name, streetnumber, address, smalldescription, type, location, icons, smallpic, blackline
FROM listing
WHERE address LIKE '%colname%'
ORDER BY name ASC
its when i have 5 WHERRE clauses that confuses me......
thanks again
vBulletin® v3.8.2, Copyright ©2000-2009, Jelsoft Enterprises Ltd.