Jump to content

Interesting Quandary Help with PHP


hank9481

Recommended Posts

I have a question that I may actually not be asking correctly as I am very much a noob. I use web forms to input data in MySQL tables and then pull that using PHP for my website. I have no issue inputting the data, but what I want to do is to pull the data back to the webform based on which option is selected, if this makes sense. Here is the code:

 

//SELECT UPDATEABLE FIELDS

$result = mysql_query("SELECT T.name, T.nickname, HM.first_name, HM.last_name, S.mgr, TR.w, TR.l, P.grade, P.in, P.out, P.x_player, P.x_text, P.bo_player, P.bo_text, P.spec_hit, P.spec_hit_text, P.spec_pitch, P.spec_pitch_text, P.question, P.review, P.year, P.outlook, P.proj, P.l1, P.l2, P.l3, P.l4, P.l5, P.l6, P.l7, P.l8, P.l9, P.sp1, P.sp2, P.sp3, P.sp4, P.sp5, P.rp FROM previews P JOIN abbr A ON P.team_id=A.team_id JOIN teams T ON P.team_id=T.team_id JOIN human_managers HM ON P.team_id=HM.team_id JOIN staffs S ON P.team_id=S.team_id JOIN team_record TR ON P.team_id=TR.team_id WHERE P.team_id='{$id}' LIMIT 1") or die(mysql_error());

while ($row = @mysql_fetch_array($result,MYSQL_ASSOC)) {

 

<select name="teamlist" onChange="window.open('previews.php?id=' + this.value);">

                            <option selected>Select a team...</option>

                            <option value="1">Baltimore Orioles</option>

                            <option value="2">Boston Red Sox</option>

 

Can someone give me an idea if this is possible or what I am doing wrong? Thanks!

Link to comment
https://forums.phpfreaks.com/topic/158663-interesting-quandary-help-with-php/
Share on other sites

No luck. Any other thoughts? Here's the updated code...

 

//SELECT UPDATEABLE FIELDS

$result = mysql_query("SELECT T.name, T.nickname, HM.first_name, HM.last_name, S.mgr, TR.w, TR.l, P.grade, P.in, P.out, P.x_player, P.x_text, P.bo_player, P.bo_text, P.spec_hit, P.spec_hit_text, P.spec_pitch, P.spec_pitch_text, P.question, P.review, P.year, P.outlook, P.proj, P.l1, P.l2, P.l3, P.l4, P.l5, P.l6, P.l7, P.l8, P.l9, P.sp1, P.sp2, P.sp3, P.sp4, P.sp5, P.rp FROM previews P JOIN abbr A ON P.team_id=A.team_id JOIN teams T ON P.team_id=T.team_id JOIN human_managers HM ON P.team_id=HM.team_id JOIN staffs S ON P.team_id=S.team_id JOIN team_record TR ON P.team_id=TR.team_id WHERE P.team_id='".$_GET['team_id']."' LIMIT 1") or die(mysql_error());

while ($row = @mysql_fetch_array($result,MYSQL_ASSOC)) {

 

<select name="idlist" onChange="window.open('previews_entry.php?team_id=' + this.value);">

                    <option selected>Select a team...</option>

                    <option value="1">Baltimore Orioles</option>

                    <option value="2">Boston Red Sox</option>

                    <option value="5">Carolina Wave</option>

                    <option value="4">New York Yankees</option>

Hi

 

Try:-

 

//SELECT UPDATEABLE FIELDS

$result = mysql_query("SELECT T.name, T.nickname, HM.first_name, HM.last_name, S.mgr, TR.w, TR.l, P.grade, P.in, P.out, P.x_player, P.x_text, P.bo_player, P.bo_text, P.spec_hit, P.spec_hit_text, P.spec_pitch, P.spec_pitch_text, P.question, P.review, P.year, P.outlook, P.proj, P.l1, P.l2, P.l3, P.l4, P.l5, P.l6, P.l7, P.l8, P.l9, P.sp1, P.sp2, P.sp3, P.sp4, P.sp5, P.rp FROM previews P JOIN abbr A ON P.team_id=A.team_id JOIN teams T ON P.team_id=T.team_id JOIN human_managers HM ON P.team_id=HM.team_id JOIN staffs S ON P.team_id=S.team_id JOIN team_record TR ON P.team_id=TR.team_id WHERE P.team_id='".$_GET['id']."' LIMIT 1") or die(mysql_error());

while ($row = @mysql_fetch_array($result,MYSQL_ASSOC)) {

 

Failing that, echo out the sql before you execute it (ie, assign the sql to a variable and echo it, then just use the variable in the mysql_query statement).

 

All the best

 

Keith

Hi

 

Like this:-

 

//SELECT UPDATEABLE FIELDS
$sql = "SELECT T.name, T.nickname, HM.first_name, HM.last_name, S.mgr, TR.w, TR.l, P.grade, P.in, P.out, P.x_player, P.x_text, P.bo_player, P.bo_text, P.spec_hit, P.spec_hit_text, P.spec_pitch, P.spec_pitch_text, P.question, P.review, P.year, P.outlook, P.proj, P.l1, P.l2, P.l3, P.l4, P.l5, P.l6, P.l7, P.l8, P.l9, P.sp1, P.sp2, P.sp3, P.sp4, P.sp5, P.rp FROM previews P JOIN abbr A ON P.team_id=A.team_id JOIN teams T ON P.team_id=T.team_id JOIN human_managers HM ON P.team_id=HM.team_id JOIN staffs S ON P.team_id=S.team_id JOIN team_record TR ON P.team_id=TR.team_id WHERE P.team_id='".$_GET['id']."' LIMIT 1";
echo "$sql <br />";
$result = mysql_query($sql) or die(mysql_error());
while ($row = @mysql_fetch_array($result,MYSQL_ASSOC)) {

 

Should give you the statement on screen

 

All the best

 

Keith

Neither suggestion has worked, but I'm not sure what I'm doing either!

 

I tested the query in phpmyadmin just to be sure it works, and it was a success. It's obviously got to be something with my WHERE clause.

 

Where is this query being executed? In what file are you trying to execute it? It should be in previews.php. Is that where it is?

Neither suggestion has worked, but I'm not sure what I'm doing either!

 

I tested the query in phpmyadmin just to be sure it works, and it was a success. It's obviously got to be something with my WHERE clause.

 

Where is this query being executed? In what file are you trying to execute it? It should be in previews.php. Is that where it is?

 

It's in previews_entry.php.

Hi

 

What has been echoed out to the screen? Can you post that up?

 

All the best

 

Keith

 

Sorry for the confusion. This was the echo-

 

Welcome, you are still logged in. SELECT T.name, T.nickname, HM.first_name, HM.last_name, S.mgr, TR.w, TR.l, P.grade, P.in, P.out, P.x_player, P.x_text, P.bo_player, P.bo_text, P.spec_hit, P.spec_hit_text, P.spec_pitch, P.spec_pitch_text, P.question, P.review, P.year, P.outlook, P.proj, P.l1, P.l2, P.l3, P.l4, P.l5, P.l6, P.l7, P.l8, P.l9, P.sp1, P.sp2, P.sp3, P.sp4, P.sp5, P.rp FROM previews P JOIN abbr A ON P.team_id=A.team_id JOIN teams T ON P.team_id=T.team_id JOIN human_managers HM ON P.team_id=HM.team_id JOIN staffs S ON P.team_id=S.team_id JOIN team_record TR ON P.team_id=TR.team_id WHERE P.team_id='' LIMIT 1

No offense man, but you need to start with some basics before jumping into queries and such.

 

Thanks for your help.

Intended to be sarcastic I'm guessing. I'll be on for about another 15minutes, post your entire page and any include pages and I'll try running through it... but my opinion of starting small stands.

Sorry for the confusion. This was the echo-

 

Welcome, you are still logged in. SELECT T.name, T.nickname, HM.first_name, HM.last_name, S.mgr, TR.w, TR.l, P.grade, P.in, P.out, P.x_player, P.x_text, P.bo_player, P.bo_text, P.spec_hit, P.spec_hit_text, P.spec_pitch, P.spec_pitch_text, P.question, P.review, P.year, P.outlook, P.proj, P.l1, P.l2, P.l3, P.l4, P.l5, P.l6, P.l7, P.l8, P.l9, P.sp1, P.sp2, P.sp3, P.sp4, P.sp5, P.rp FROM previews P JOIN abbr A ON P.team_id=A.team_id JOIN teams T ON P.team_id=T.team_id JOIN human_managers HM ON P.team_id=HM.team_id JOIN staffs S ON P.team_id=S.team_id JOIN team_record TR ON P.team_id=TR.team_id WHERE P.team_id='' LIMIT 1

 

Looks like nothing has been passed in for the id field in the query string.

 

Do this near the top of the script and see what values are passed in:-

 

foreach ($_GET as $Field => $Value) echo "$Field  $Value  <br />";

 

In you code examples you have passed id (first one) and team_id (second one). Which are you using at the moment?

 

All the best

 

Keith

Sorry for the confusion. This was the echo-

 

Welcome, you are still logged in. SELECT T.name, T.nickname, HM.first_name, HM.last_name, S.mgr, TR.w, TR.l, P.grade, P.in, P.out, P.x_player, P.x_text, P.bo_player, P.bo_text, P.spec_hit, P.spec_hit_text, P.spec_pitch, P.spec_pitch_text, P.question, P.review, P.year, P.outlook, P.proj, P.l1, P.l2, P.l3, P.l4, P.l5, P.l6, P.l7, P.l8, P.l9, P.sp1, P.sp2, P.sp3, P.sp4, P.sp5, P.rp FROM previews P JOIN abbr A ON P.team_id=A.team_id JOIN teams T ON P.team_id=T.team_id JOIN human_managers HM ON P.team_id=HM.team_id JOIN staffs S ON P.team_id=S.team_id JOIN team_record TR ON P.team_id=TR.team_id WHERE P.team_id='' LIMIT 1

 

Looks like nothing has been passed in for the id field in the query string.

 

Do this near the top of the script and see what values are passed in:-

 

foreach ($_GET as $Field => $Value) echo "$Field  $Value  <br />";

 

In you code examples you have passed id (first one) and team_id (second one). Which are you using at the moment?

 

All the best

 

Keith

 

The actual field is called team_id so I assume I need to actually use that, yes?

Also, I input the foreach clause you requested just after the while clause. It didn't seem to change a thing as the result is the same-

 

Welcome, you are still logged in. SELECT T.name, T.nickname, HM.first_name, HM.last_name, S.mgr, TR.w, TR.l, P.grade, P.in, P.out, P.x_player, P.x_text, P.bo_player, P.bo_text, P.spec_hit, P.spec_hit_text, P.spec_pitch, P.spec_pitch_text, P.question, P.review, P.year, P.outlook, P.proj, P.l1, P.l2, P.l3, P.l4, P.l5, P.l6, P.l7, P.l8, P.l9, P.sp1, P.sp2, P.sp3, P.sp4, P.sp5, P.rp FROM previews P JOIN abbr A ON P.team_id=A.team_id JOIN teams T ON P.team_id=T.team_id JOIN human_managers HM ON P.team_id=HM.team_id JOIN staffs S ON P.team_id=S.team_id JOIN team_record TR ON P.team_id=TR.team_id WHERE P.team_id='' LIMIT 1

Hi

 

The foreach is there to show you all the fields passed in and their values. Put it very near the top. If you put it in the while clause and the SQL is not bringing anything back or fails then the foreach will not be executed.

 

All the best

 

Keith

 

Okay I put the foreach loop at the very top and this is all that it did-

 

Welcome, you are still logged in. team_id 14

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.