/    Sign up×
Community /Pin to ProfileBookmark

building a URL & a db query

I am building a URL and a SELECT query at the same time. I have a GET method form on search.php. It sends the user to searchResults.php where I am retrieving searchStatus:

[code=php]<?php
if ( !empty($_GET[‘searchStatus’]) ) # if searched
{
$_SESSION[‘status’] = mysql_real_escape_string($_GET[‘searchStatus’]); # get selected status from previous page
$searchStatus = $_SESSION[‘status’];
$querySearch.= “AND vigil_call.status_num = ‘$searchStatus’ “;
}
if ( !empty($_GET[‘refreshStatus’]) ) # if refreshed, grab session from URL
{
$refreshStatus = mysql_real_escape_string($_GET[‘refreshStatus’]);
$querySearch.= “AND vigil_call.status_num = ‘$refreshStatus’ “;
}
?>[/code]

If the user is sent from the previous page, then the query is built with the searched status. However, this results page is auto refreshed. On the refresh, I am trying to display the same results … just updated. So, I am grabbing the session from the newly built URL.

[code=php]<?php
# build URL
$url = “?lastCall=” . $_SESSION[‘dbLast’] . “&refreshEagle=” . $_SESSION[‘eagle’] . “&refreshStatus=” . $_SESSION[‘status’] .
“&refreshHall=” . $_SESSION[‘hall’]. “&refreshTech=” . $_SESSION[‘tech’];
?>[/code]

I am testing by echoing the values of the 2 variables and it correctly echoes a duplicate number:

[code=php]<?php
echo “status: ” . $_SESSION[‘status’];
echo “<br>refresh status: ” . $refreshStatus;
?>[/code]

The query is successful when first reaching the page and I get my results, but upon refresh the I have no results. Undecided Can someone be of assistance? Or maybe you know of an easier/cleaner method to achieve the same effect?

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@rbraggauthorAug 03.2007 — Or better yet - why wouldn't this work for both initial displaying and refreshes?

[code=php]# build URL
$url = "?lastCall=" . $_SESSION['dbLast'] . "&refreshEagle=" . $_SESSION['eagle'] . "&searchStatus=" . $_SESSION['status'] . "&refreshHall=" . $_SESSION['hall']. "&refreshTech=" . $_SESSION['tech'];

if ( !empty($_GET['searchStatus']) )
{
$_SESSION['status'] = mysql_real_escape_string($_GET['searchStatus']);
$searchStatus = $_SESSION['status'];
$querySearch.= "AND vigil_call.status_num = '$searchStatus' ";
}[/code]
Copy linkTweet thisAlerts:
@NogDogAug 03.2007 — If $_GET['searchStatus']) and $_SESSION['status'] both exist and have different values, then the query result will be empty since you are AND'ing them in the query to both be equal to vigil_call.status_num.
Copy linkTweet thisAlerts:
@rbraggauthorAug 06.2007 — Hi again, NogDog and thanks for your reply. I understand your explanation and yet still can't wrap my brain around a method for doing what I am trying to do.

I am probably just making things overly complicated, which I am an expert at doing. I would just simply like the same search query to rerun at every auto-refresh as to redisplay the results ... only updated. Any suggestions? ?
Copy linkTweet thisAlerts:
@rbraggauthorAug 07.2007 — I should mention that they should never have different values. Since I am refreshing, the GET and the SESSION equal each other.
Copy linkTweet thisAlerts:
@rbraggauthorAug 07.2007 — I've been reading about $QUERY_STRING. I'm not really familiar with it but I wonder if using it in the refresh URL could be beneficial for me?
Copy linkTweet thisAlerts:
@NogDogAug 07.2007 — It's a bit hard trying to figure out what's going on from those brief snippets (or at least it is for me). My suggestion would be to do a little debug output if things don't go the way you expect when you execute the query:
[code=php]
$result = mysql_query($querySearch);
// DEBUG:
ini_set('display_errors', 1); // just in case it's not on
error_reporting(E_ALL); // ditto
if(!$result)
{
user_error("Query failed ($querySearch) - " . mysql_error());
}
elseif(mysql_num_rows($result) == 0)
{
user_error("No rows returned by query ($querySearch)");
}
// END DEBUG
[/code]
Copy linkTweet thisAlerts:
@rbraggauthorAug 07.2007 — Thanks for your reply. I have configured my code until I no longer have an error from the debugging. I am making progress. Now upon refresh, I get results from my 2nd to last search instead of my last search:
[code=php]# build URL
$url = "$PHP_SELF?lastCall=" . $_SESSION['dbLast'] . "&searchHall=" . $_SESSION['searchHall'] . "&searchRoom=" . $_SESSION['searchRoom'] . "&searchSpace=" . $_SESSION['searchSpace'] . "&searchStatus=" . $searchstatus . "&searchTech=" . $_SESSION['searchTech'];[/code]

[code=php]$_SESSION['searchStatus'] = mysql_real_escape_string($_GET['searchStatus']);

if ( !empty($_SESSION['searchStatus']) )
{
$refreshStatus = $_SESSION['searchStatus'];
$querySearch.= "AND vigil_call.status_num = '$refreshStatus'";
}[/code]

I imagine this has something to do with using sessions?
×

Success!

Help @rbragg spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...