Jump to content

SQL table query result not passing to POST string


twittoris

Recommended Posts

I am retrieving a rowfrom a table and when I post the row variable it doesnt read it.

___

$query = "SELECT * FROM $tbl_name";

 

$result = mysql_query($query) or die(mysql_error());

 

while($row = mysql_fetch_array($result)){

echo $row['name'];

echo "<br />";

 

$postinfo = 'p_doctor_name=' . $row .'&p_name_type=A&p_search_type=BEGINS';

__

This outputs p_entity_name=&p_name_type=A&p_search_type=BEGINS

Note that it is missing $row

 

Do I need to put it in an array?

Link to comment
Share on other sites

I can think of a few reasons you might be having an issue.  If you solved this already then great, but I'd still like to put in my $0.02 (two cents.)

 

First, unless you're just not posting it, I don't see an end to your while loop.  You're missing the closing }

 

Next, you're using mysql_fetch_array, which returns a numerically-indexed array, not an associative array, yet you're trying to get the value from the result using $row['name'], you should change mysql_fetch_array() to mysql_fetch_assoc().

 

And finally, $row is an array, not a string, so when echoing it you're only going to get this:

 

Array()

 

What you should do is something like this:

 

$query = mysql_query("SELECT * FROM $tbl_name") or die(mysql_error());

while($row = mysql_fetch_assoc($query)) {
  echo = "p_doctor_name=" . $row['name'] . "&p_name_type=A&p_search_type=BEGINS";
  echo "<br>\n";
  }

 

This will print the POST info that you want.  Alternatively, if you want to use the POST info later in the script, you could change the first echo line in the loop, to this:

 

$postinfo[] = "p_doctor_name=" . $row['name'] . "&p_name_type=A&p_search_type=BEGINS";

 

And remove the echo "<br>\n"; line.  That will create an array containing each of the lines, which you can then iterate through in a foreach loop.

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.