PDA

View Full Version : Problem accessing array data from a link.


songboy
09-29-2010, 10:58 PM
I have code which creates an alphabet array and then echoes the alphabet as links. When, for example, you click on H the action gets sent to another script (see below).
$letter_chosen = $_SESSION['letter_chosen'];
<?php $query = ("SELECT writing_first_name, writing_second_name, user_name FROM writer_page_details WHERE writing_second_name LIKE '$letter_chosen%' ORDER BY writing_second_name");
$result = mysqli_query($cxn, $query);
@$names = mysqli_fetch_assoc($result);
The code above selects names from the database where the surname begins eg with a H.
Now these names are echoed and again, the surname word becomes a link to that persons web page (see below).
<form action = "writer_list_page.php" method="GET" onClick="document.forms[0].submit();">
<table width='841' cellspacing='0' cellpadding='0' class='tableheight'>
<?php
$i=1;
do {
?>
<tr>
<td width="97"class='tabcolumns1'> <?php echo "$i";?> </td>
<td width="253"class='tabcolumns'><?php echo "<a href=\"?name=" . $names['writing_second_name'] . "\">" . $names['writing_second_name'] . "</a>&nbsp;&nbsp;&nbsp;&nbsp;";?></td>
<td width="244"class='tabcolumns'><?php echo $names['writing_first_name'];?></td>
</tr>
<?php $i++;}while ($names = mysqli_fetch_assoc($result));
Now I create this variable:
@$chosen_name = $_GET['name'];
Next, I do this:
$query1 = ("SELECT * FROM writer_page_details WHERE writing_second_name = '$chosen_name'");
$result1 = mysqli_query($cxn, $query1) or die("Can't process query.");
$new_array = mysqli_fetch_assoc($result1);
I now create variables and sessions based on all the data set against the chosen name. All this is sent to dynamically create the users page.
Here's the problem. I have two sets of test data matching the alphabet choice of H:
Hur Ben
Hur Fred
If I click Hur, as in Ben, Ben Hur's page is created. However, then I realised that if I click Hur, as in Fred, exactly the same page is created as previously (ie Ben Hur's data is found again). It's finding the first Hur all the time, regardless of the first name or any other part of the data row I call.
How can I click on Hur and get the right person's data. My name link is only recognising the surname yet the data array contains all the keys that link to that name (ie from the DB row). For example, when I use writing_first_name in the SELECT query it has no effect on what data is collected from the DB. Whether it's Ben or Fred, I always get Ben's data.
I've been stuck on this for two weeks ! If you can see the problem I would be grateful for a solution.
Thanks -
Songboy

davidj
09-30-2010, 03:32 PM
WHOA.....

add some code tags mate. Im not the borg!

songboy
09-30-2010, 05:40 PM
I have code which creates an alphabet array and then echoes the alphabet as links. When, for example, you click on H the action gets sent to another script (see below).
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>writer list page</title>
</head>
<body>
<?php
$letter_chosen = $_SESSION['letter_chosen'];
?>
<?php
$query = ("SELECT writing_first_name, writing_second_name, user_name FROM writer_page_details WHERE writing_second_name LIKE '$letter_chosen%' ORDER BY writing_second_name");
$result = mysqli_query($cxn, $query);
@$names = mysqli_fetch_assoc($result);
?>
The code above selects names from the database where the surname begins eg with a H.
Now these names are echoed and again, the surname word becomes a link to that persons web page (see below).

<form action = "writer_list_page.php" method="GET" onClick="document.forms[0].submit();">
<table width='841' cellspacing='0' cellpadding='0' class='tableheight'>
<?php
$i=1;
do {
?>
<tr>
<td width="97"class='tabcolumns1'> <?php echo "$i";?> </td>
<td width="253"class='tabcolumns'><?php echo "<a href=\"?name=" . $names['writing_second_name'] . "\">" . $names['writing_second_name'] . "</a>&nbsp;&nbsp;&nbsp;&nbsp;";?></td>
<td width="244"class='tabcolumns'><?php echo $names['writing_first_name'];?></td>
</tr>
<?php $i++;}while ($names = mysqli_fetch_assoc($result));?>
</table>
Now I create this variable:
<?php @$chosen_name = $_GET (?php@$chosen_name = $_GET)['name'];?>
Next, I do this:
<?php $query1 = ("SELECT * FROM writer_page_details WHERE writing_second_name = '$chosen_name'");
$result1 = mysqli_query($cxn, $query1) or die("Can't process query.");
$new_array = mysqli_fetch_assoc($result1);?>
</body>
</html>
I now create variables and sessions based on all the data set against the chosen name. All this is sent to dynamically create the users page.
Here's the problem. I have two sets of test data matching the alphabet choice of H:
Hur Ben
Hur Fred
If I click Hur, as in Ben, Ben Hur's page is created. However, then I realised that if I click Hur, as in Fred, exactly the same page is created as previously (ie Ben Hur's data is found again). It's finding the first Hur all the time, regardless of the first name or any other part of the data row I call.
How can I click on Hur and get the right person's data. My name link is only recognising the surname yet the data array contains all the keys that link to that name (ie from the DB row). For example, when I use writing_first_name in the SELECT query it has no effect on what data is collected from the DB. Whether it's Ben or Fred, I always get Ben's data.
I've been stuck on this for two weeks ! If you can see the problem I would be grateful for a solution.
Thanks -
Songboy

davidj
09-30-2010, 07:13 PM
nope

highlight the code in your post and click the php button so the [php] tags wrap it

songboy
09-30-2010, 09:40 PM
I have code which creates an alphabet array and then echoes the alphabet as links. When, for example, you click on H the action gets sent to another script. The letter chosen gets a variable.

$letter_chosen = $_SESSION['letter_chosen'];

Using the chosen letter variable I initiate a data search.
$query = ("SELECT writing_first_name, writing_second_name, user_name FROM writer_page_details WHERE writing_second_name LIKE '$letter_chosen%' ORDER BY writing_second_name");
$result = mysqli_query($cxn, $query);
@$names = mysqli_fetch_assoc($result);

The code above selects names from the database where the surname begins eg with a H. But it also gets a first name and a user name
Now the surname and first names are echoed and again, the surname word becomes a link to that persons web page (see below).

<form action = "writer_list_page.php" method="GET" onClick="document.forms[0].submit();">
<table width='841' cellspacing='0' cellpadding='0' class='tableheight'>

$i=1;
do {

<tr>
<td width="97"class='tabcolumns1'> echo "$i"; </td>
<td width="253"class='tabcolumns'> echo "<a href=
\"?name=" . $names['writing_second_name'] . "\">" . $names['writing_second_name'] . "</a>&nbsp;&nbsp;&nbsp;&nbsp;"; </td>
<td width="244"class='tabcolumns'> echo $names['writing_first_name'];</td>
</tr>
$i++;}while ($names = mysqli_fetch_assoc($result));
</table>

Now I create this variable:
@$chosen_name = $_GET['name'];

Next, I do this:
$query1 = ("SELECT * FROM writer_page_details WHERE writing_second_name = '$chosen_name'");
$result1 = mysqli_query($cxn, $query1) or die("Can't process query.");
$new_array = mysqli_fetch_assoc($result1);


I now create variables and sessions based on all the data set against the chosen name. All this is sent to dynamically create the users page.
Here's the problem. I have two sets of test data matching the alphabet choice of H:
Hur Ben
Hur Fred
If I click Hur, as in Ben, Ben Hur's page is created. However, then I realised that if I click Hur, as in Fred, exactly the same page is created as previously (ie Ben Hur's data is found again). It's finding the first Hur all the time, regardless of the first name or any other part of the data row I call.
How can I click on Hur and get the right person's data. My surname link is only recognising the surname yet the data array contains all the keys that link to that name (ie from the DB row). For example, when I use writing_first_name in the SELECT query it has no effect on what data is collected from the DB. Whether it's Ben or Fred, I always get Ben's data.
I've been stuck on this for two weeks ! If you can see the problem I would be grateful for a solution.
Thanks -
Songboy

davidj
10-01-2010, 05:40 AM
you should have a unique identifier for each result and pass that id in