Database custom table issues – incorrect result displayed
-
I tried to put code in the backticks like it says, so just ignore any ”s that look out of place (unless it’s blatantly not me trying to do that)
First things first:
I’ve spent most of today going over these forums;
the stackoverflow forums;
the php.net manual; and
a bunch of random sites I found through Google Search – so,
if I’ve missed the answer and it seems like I’m asking an already answered question I’m sorry.
I’ve probably just been looking at the same problem for way too long and nothing is making sense.The background:
We’ve inserted some custom tables into the wordpress database, so I can connect to these tables through $wpdb. The code for the working connections is as follows:
‘global $wpdb;
// get list of localities
$localityRow = $wpdb->get_results( “SELECT * FROM tblYBSLocality ORDER BY Name ASC” );
// get list of schools
$schoolRow = $wpdb->get_results( “SELECT * FROM tblYBSSchool ORDER BY Name ASC” );
// get school ID if form has been submitted
$SelectedSchoolID = $_GET[‘schools’];
// get location ID if form has been submitted
$SelectedLocationID = $_GET[‘localities’];’Then later in my page I make it do stuff (scorcery!)
‘// Create a drop down box for the user to select their location (and one has been done for school but I left that out because you get the idea
<select name=”localities” style=”width: 300px”>
<?php
foreach ($localityRow as $locality) {
$LocalityID = $locality->LocalityID;
$LocalityName = $locality->Name;
?><option value=<?php echo $LocalityID; ?> <?php if(isset($SelectedLocationID) &&
$SelectedLocationID == $LocalityID) print(” selected”)?>><?php echo $LocalityName;?>
</option>
<?php
}
?>
</select>’Note – Yes I know using * is bad, I’ll fix that later – right now I just want it to work.
Using this I can then go through and generate a bunch of stuff using the following:
‘// get school ID if form has been submitted
$SelectedSchoolID = $_GET[‘schools’];
// get location ID if form has been submitted
$SelectedLocationID = $_GET[‘localities’];’This isn’t really important to the rest of my issue, so I’ll move on.
The issue:
I’ll start with the code. This is supposed to connect to some other tables and do stuff – based on the connections and data retrieved above:
‘$selectedSchoolName = $wpdb->get_results( “SELECT Name FROM tblYBSSchool WHERE SchoolID=”.$SelectedSchoolID );
// get selected location name
$selectedLocationName = $wpdb->get_results( “SELECT Name FROM tblYBSLocality WHERE LocalityID=”.$SelectedLocationID );
// get route ID
$getRouteID = $wpdb->get_results( “SELECT * FROM tblYBSRoute WHERE RouteID IN ( SELECT RouteID FROM tblYBSRouteSchool WHERE SchoolID =”.$SelectedSchoolID.”)”.$SelectedLocationID);’Now, I THINK the issue comes with the “.$SelectedSchoolID ); part (and the location one but this is already getting TLDR).
What I want to do later in the page (once the user has made their selections and submitted the form), is get results (fancy that!).
There are 2 parts to the results:
1st I want to say “Search results for routes between:” the location name and the school name.
2nd, I want to display those results. But I can’t even get past the 1st point, so let’s fix that first.I have tried 3 different approaches:
‘// FIRST APPROACH
// This kinda works, it echoes the last locality name from the table which is better than nothing
<b><?php echo $LocalityName;?></b> and <b><?php echo $SchoolName;?></b>// SECOND APPROACH
// This gives me the white page of death. Which is hilarious because it’s pretty much the exact same as what was used in the option – which worked
<b><?php if(isset($SelectedLocationID) && $SelectedLocationID == $LocalityID) echo $LocalityName;?></b> and <b><?php if(isset($SelectedSchoolID) && $SelectedSchoolID == $SchoolID) echo $SchoolName;?></b>// THIRD APPROACH
// This also gives me the white page of death. And now I’m out of ideas.
<b><?php if(isset($SelectedLocationID) && $selectedLocationName == $LocalityName echo $LocalityName ;?></b> and <b><?php if(isset($SelectedSchoolID) && $selectedSchoolName == $SchoolName echo $SchoolName ;?></b>’In my head (HAH!) the last 2 should work. Am I correct in thinking that it’s the “.$SelectedSchoolID ); part? Or have I forked something else up entirely?
Sorry for the TLDRness, but I thought I should provide as much detail as possible.
Any and all help is greatly appreciated. I’m going to go smack my head into the desk a few times now ??
- The topic ‘Database custom table issues – incorrect result displayed’ is closed to new replies.