Page 1 of 1

PHP code problems

Posted: Mon Oct 18, 2004 7:18 pm
by C++Casey
nigma | Help us, help you. Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Hi...I'm working on a website http://searchbanks.com/search.php...on that page you will see 12-13 different checkboxes where a user can mark a check in the checkbox and search that various category... the code for that I will attach after my question.

My problem is I'm having a difficult time converting those checkbox options to text links instead.  So for example instead of having the user search by putting a check in the check box I want a link that says "Lending" where the user can just click on the link and have the same results as what they had with the check box.

How would I go about this?  A sample code would be excellent.

Here is the current code with the check box. FYI the results are being pulled from a database.

Code: Select all

<?php

require "xxx.php";
require "xxx.php";

$hugeres = SQLact("query", "SELECT * FROM freelancers_bans WHERE ip='" . $REMOTE_ADDR . "'");
$hugerows = SQLact("num_rows", $hugeres);
if ($hugerows==0) {
include ("header.php");
if ($showstatus == "open") {
?>
<b><big>Project Search Results</big></b><br><small>
Status: open<br>
</small>
<p>
<table width="100%" border="<? echo $tableborder; ?>" cellspacing="<? echo $tablecellsp; ?>" cellpadding="<? echo $tablecellpa; ?>">
<tr>
<td bgcolor="<? echo $tablecolorh; ?>" width=150><b><font color=<? echo $tablecolort; ?>>Project Name</td>
<td bgcolor="<? echo $tablecolorh; ?>"><b><font color=<? echo $tablecolort; ?>>Job Type</td>
<td bgcolor="<? echo $tablecolorh; ?>"><b><font color=<? echo $tablecolort; ?>>Bids</td>
<td bgcolor="<? echo $tablecolorh; ?>"><b><font color=<? echo $tablecolort; ?>>Status</td>
<td bgcolor="<? echo $tablecolorh; ?>"><b><font color=<? echo $tablecolort; ?>>Start Date</td>
</tr>
<?php
$result = SQLact("query", "SELECT * FROM freelancers_projects WHERE status='open' ORDER BY date2 DESC");
$rows = SQLact("num_rows", $result);
if ($rows==0) {
echo '<tr>
<td bgcolor="' . $tablecolor1 . '" colspan="5" align="center">(No open projects found.)</td>
</tr>';
} else {
while ($row=SQLact("fetch_array", $result)) {
?>
<tr>
<td bgcolor="<? echo $tablecolor1; ?>"><a href="<? echo $siteurl; ?>/project.php?id=<? echo $row[id]; ?>"><? echo $row[project]; ?></a><?
if ($row[special] == "featured") {
echo ' <a href="' . $siteurl . '/featured.php"><img src="' . $siteurl . '/images/featured.gif" alt="Featured Project!" border=0></a>';
} else {}
$secondsPerDay9 = ((24 * 60) * 60);
$timeStamp9 = time();
$daysUntilExpiry9 = $row[expires];
$getdat9 = $timeStamp9 + ($daysUntilExpiry9 * $secondsPerDay9);
$thedat9 = $getdat9-$timeStamp9;
$realdat9 = round($thedat9/((24 * 60) * 60));
$explod9 = explode('-', $projectudays);
for ($i9=0;$i9<count($explod9);$i9++) {
if ($realdat9==$explod9[$i9]) {
echo ' <img src="' . $siteurl . '/images/urgent.gif" alt="Urgent!" border=0>';
}
}
?></td>
<td bgcolor="<? echo $tablecolor1; ?>"><?php
$archway = $row[categories];
$len=strlen($archway);
$boink=substr("$archway", 0, ($len-2));
echo $boink;
?></td>
<td bgcolor="<? echo $tablecolor1; ?>"><?
$result2 = SQLact("query", "SELECT * FROM freelancers_bids WHERE id='" . $row[id] . "'");
$rows2 = SQLact("num_rows", $result2);
echo $rows2;
?></td>
<td bgcolor="<? echo $tablecolor1; ?>"><font color=green><b>open</td>
<td bgcolor="<? echo $tablecolor1; ?>"><? echo $row[creation]; ?></td>
</tr>
<?php
}
}
?>
</table>
<small><? echo $rows; ?> project<?
if ($rows!==1) {
echo 's';
} else {}
?> found.</small><p>
<small><a href="<? echo $siteurl; ?>/search.php">Perform Another Search...</a></small><p>
<?php
} else {
if (!$submit) {
?>




<center>
<big><b>Search Projects</b></big>
<p>
<form method="POST" action="search.php">
<div align="center"><center>
<b>Status:</b>
<select name="status" size="1">
<option selected value="">Any</option>
<option value="open">Open</option>
<option value="frozen">Frozen</option>
<option value="closed">Closed</option>
</select>
<input type="submit" value="Search" name="submit">
<p>
<b>Keywords:</b> <input type="text" name="keywords" value="" size="20">
<p>
<table>
<tr><td>
<b>Job Type:</b><br>
<?php
$selectcats = SQLact("query", "SELECT * FROM freelancers_cats");
$i=0;
while ($row=SQLact("fetch_array", $selectcats)) {
$i++;
?>
<input type="checkbox" name="category[]" value="<? echo $row[categories]; ?>"> <? echo $row[categories]; ?><br>
<?php
}
?>
</td></tr>
</table>
  </center></div>
</form>
<?php
} else {
if (is_array($category)) {
$query = "SELECT * FROM freelancers_projects WHERE categories LIKE '";
foreach ($category as $key=>$val) {
$query .= "%" . $val . "%";
}
$query .= "' AND ";
} else {
$query = "SELECT * FROM freelancers_projects WHERE ";
}
if ($status == "") {
$query .= "project LIKE '%$keywords%' ORDER BY date2 DESC";
} else {
$query .= "status LIKE '$status' AND project LIKE '%$keywords%' ORDER BY date2 DESC";
}
$lolres = SQLact("query", $query);
$rows = SQLact("num_rows", $lolres);
?>
<b><big>Project Search Results</big></b><br><small>
Status: <?
if ($status == "") {
echo "all";
} else {
echo $status;
}
?><br>
</small>
<p>
<table width="100%" border="<? echo $tableborder; ?>" cellspacing="<? echo $tablecellsp; ?>" cellpadding="<? echo $tablecellpa; ?>">
<tr>
<td bgcolor="<? echo $tablecolorh; ?>" width=150><b><font color=<? echo $tablecolort; ?>>Project Name</td>
<td bgcolor="<? echo $tablecolorh; ?>"><b><font color=<? echo $tablecolort; ?>>Job Type</td>
<td bgcolor="<? echo $tablecolorh; ?>"><b><font color=<? echo $tablecolort; ?>>Bids</td>
<td bgcolor="<? echo $tablecolorh; ?>"><b><font color=<? echo $tablecolort; ?>>Status</td>
<td bgcolor="<? echo $tablecolorh; ?>"><b><font color=<? echo $tablecolort; ?>>Start Date</td>
</tr>
<?php
if ($rows!==0) {
while ($row=SQLact("fetch_array", $lolres)) {
?>
<tr>
<td bgcolor="<? echo $tablecolor1; ?>"><a href="<? echo $siteurl; ?>/project.php?id=<? echo $row[id]; ?>"><? echo $row[project]; ?></a><?
if ($row[special] == "featured") {
echo ' <a href="' . $siteurl . '/featured.php"><img src="' . $siteurl . '/images/featured.gif" alt="Featured Project!" border=0>';
} else {}
$secondsPerDay9 = ((24 * 60) * 60);
$timeStamp9 = time();
$daysUntilExpiry9 = $row[expires];
$getdat9 = $timeStamp9 + ($daysUntilExpiry9 * $secondsPerDay9);
$thedat9 = $getdat9-$timeStamp9;
$realdat9 = round($thedat9/((24 * 60) * 60));
$explod9 = explode('-', $projectudays);
for ($i9=0;$i9<count($explod9);$i9++) {
if ($realdat9==$explod9[$i9]) {
echo ' <img src="' . $siteurl . '/images/urgent.gif" alt="Urgent!" border=0>';
}
}
?></a></td>
<td bgcolor="<? echo $tablecolor1; ?>"><?php
$archway = $row[categories];
$len=strlen($archway);
$boink=substr("$archway", 0, ($len-2));
echo $boink;
?></td>
<td bgcolor="<? echo $tablecolor1; ?>"><?
$y4res = SQLact("query", "SELECT * FROM freelancers_bids WHERE id='" . $row[id] . "'");
echo SQLact("num_rows", $y4res);
?></td>
<td bgcolor="<? echo $tablecolor1; ?>"><?
if ($row[status] == "open") {
echo '<font color="green"><b>' . $row[status] . '</font>';
} else if ($row[status] == "frozen") {
echo '<font color="blue"><b>' . $row[status] . '</font>';
} else {
echo '<font color="red"><b>closed</font>';
}?></td>
<td bgcolor="<? echo $tablecolor1; ?>"><? echo $row[creation]; ?></td>
</tr>
<?php
}
} else {
echo '<tr>
<td bgcolor="' . $tablecolor1 . '" colspan="5" align="center">(No projects found.)</td>
</tr>';
}
?>
</table>
<small><? echo $rows; ?> project<?
if ($rows!==1) {
echo 's';
} else {}
?> found.</small><p>
<small><a href="<? echo $siteurl; ?>/search.php">Perform Another Search...</a></small><p>
<?php
}
}
include ("footer.php");
} else {
echo 'You have been banned from using ' . $companyname . '!<br>
You do not have access to any services used in this section of the website!<br>
The reason for your ban is:<br>
<b><i>';
$humanres = SQLact("query", "SELECT * FROM freelancers_bans WHERE ip='" . $REMOTE_ADDR . "'");
$rrreason = SQLact("result", $humanres,0,"reason");
if ($rrreason == "") {
echo 'No reason was given for your ban.';
} else {
echo $rrreason;
}
echo '</i></b><br><br>
If you think there has been a mistake, contact ' . $emailaddress;
}
?>
nigma | Help us, help you. Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Mon Oct 18, 2004 7:59 pm
by kettle_drum
Too much code to read through, but.

All you need to do is have the links add that name to the url and then add this into the search query.

With checkboxes you would go through them all and add them to the query if they were checked - you do the same with the value in the url that the link points the user to. Check to see if there is any value in the url - if there is add it to the query.

Posted: Mon Oct 18, 2004 9:13 pm
by C++Casey
Thanks for the advice...the problem is the query used by the checkboxes is a self query so the search.php loads again without any values you can try it yourself and see what i mean at http://searchbanks.com/search.php

Convert Checkboxes values to Text links

Posted: Mon Oct 18, 2004 10:40 pm
by C++Casey
OK...sorry about posting the long code here is a slim down verison. What I'm trying to do is covert a search feture that uses checkboxes to a search function that uses text links. I can't figure it out...Any help is appreciated.

Code: Select all

<?php
$selectcats = SQLact("query", "SELECT * FROM freelancers_cats");
$i=0;
while ($row=SQLact("fetch_array", $selectcats)) {$i++;?>

<input type="checkbox" name="category[]" value="<? echo $row[categories]; ?>">
 
<? echo $row[categories]; ?>

<br>
<?php
}
?>
</td>
</tr>
</table>  
</center>
</div>
</form>
<?php
} else {if (is_array($category)) {
$query = "SELECT * FROM freelancers_projects WHERE categories LIKE '";
foreach ($category as $key=>$val) {$query .= "%" . $val . "%";}$query .= "' AND ";} 
else {$query = "SELECT * FROM freelancers_projects WHERE ";}
if ($status == "") 
{$query .= "project LIKE '%$keywords%' ORDER BY date2 DESC";} 
else {$query .= "status LIKE '$status' AND project LIKE '%$keywords%' ORDER BY date2 DESC";}
$lolres = SQLact("query", $query);$rows = SQLact("num_rows", $lolres);?>
?>

no biggie

Posted: Mon Oct 18, 2004 10:49 pm
by neophyte
so build the link with a query string like:

Code: Select all

&lt;a href="search.php?query=lending"&gt;Lending&lt;/a&gt;
And then include an if statement like:

Code: Select all

if (isset($_GET['query']){

//EXECUTE THE QUERY AND DISPLAY RESULTS

}

Posted: Mon Oct 18, 2004 10:51 pm
by feyd
okay... so you want these new text links to submit the form using what they've typed into the text box? Unless the text to search for is already known, this basically requires Javascript, or some other client-side scripting.



sidenote: your page design assumes a white browser background. Mine isn't white, it looks a bit odd. :)

Posted: Tue Oct 19, 2004 12:13 am
by C++Casey
Hi Feyd

All I'm trying to do is build text links, I do not want them to submit the form or be inside the form. I'm going to try what neophyte suggested. Any suggestions that you or others may have will be helpful. Thanks

PHP code problems

Posted: Tue Oct 19, 2004 4:45 am
by C++Casey
Hi everyone

I'm newbie just picking up PHP...where would I paste the following code in this program. Here is the code that another user recommended I use.

Code: Select all

<?php
if (isset($_GET['query']){//EXECUTE THE QUERY AND DISPLAY RESULTS}
?>
and what would you suggest I put in between the brackets for the above code
{//EXECUTE THE QUERY AND DISPLAY RESULTS}

I appreciate all your help, I'm just trying to learn this new language along with 5 others 8O

Posted: Tue Oct 19, 2004 5:02 am
by phpScott
I think what you are trying to do is to have the use click on some text links, allow them to choose multiple links then have a submit button to process those links, right?

I think this is the type of thing that you are looking for, its done without a submit button and would require more work but it's a start.

Code: Select all

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

<html>
<head>
<title>Untitled</title>
<script language="JavaScript" type="text/javascript">
<!--
function addToQuery(val)
&#123;
  curQuery=document.getElementById('query').value;
	curQuery=curQuery+val+';';
	document.getElementById('query').value=curQuery;
&#125;
//-->
</script>

</head>
<body>
BANKS:<br />
<a href="javascript: addToQuery('Halifax');">Halifax</a><br />
<a href="javascript: addToQuery('RBOS');">Royal Bank of Scotland</a><br />
<a href="javascript: addToQuery('NatWest');">NatWest</a><br />
Accounts:<br />
<a href="javascript: addToQuery('Savings');">Savings</a><br />
<a href="javascript: addToQuery('Current');">Current</a><br />
<a href="javascript: addToQuery('Investment');">Investment</a><br />

field should be hidden but here for testing
<input type="text" name="query" id="query" value="" />
</body>
</html>
copy and paste it to see if it is the type of thing that you are looking for.

phpScott

PHP Code Fix

Posted: Tue Oct 19, 2004 4:50 pm
by C++Casey
Thanks for all the replies...you guys are awesome...i got everything to work and ended up using the following code

Code: Select all

<?php
$colname_rsSearch = "1";
if (isset($_GET['categories'])) {
  $colname_rsSearch = (get_magic_quotes_gpc()) ? $_GET['categories'] : addslashes($_GET['categories']);
}

?>