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
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>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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).

 

Can you clarify this a little bit more? I'm a complete amateur at this.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.