SunQuest
           PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
You eat, breathe and sleep innovation. Build your mobile intelligence with BlackBerry® experts this July. Register Today!
  #1  
Old August 1st, 2002, 03:13 PM
AaaDee AaaDee is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Huddersfield, West Yorkshire, UK
Posts: 4 AaaDee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via Yahoo to AaaDee
Different Values

Hi,

i have a page that

$sql = "SELECT * FROM skills
WHERE skill_from_last_page = $skill";

i have a

while ($row = mysql_fetch_array($sql_result))
{
$skill2 = $row["skill2"];

}

$skill2

Which brings back 9 rows of $skill2.

Ok, the next page

$sql = "SELECT * FROM skills2
WHERE skill_from_last_page = $skill2";

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

$skill3 = $row["skill3"];

}

but bcos
$skill2 is the same value ($skill2) for each row, it overwrites each row and just selects the last row from the database.

Any help of how to set each value a setting so this will work?

Adam




Reply With Quote
  #2  
Old August 1st, 2002, 10:09 PM
Taoism Taoism is offline
Contributing User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Winnipeg, MB, Canada
Posts: 81 Taoism User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 30 sec
Reputation Power: 2
RE: Different Values

something like this? (untested for bugs/errors)
php Code:
Original - php Code
  1.  
  2. <?php
  3. //first page
  4. $sql = "SELECT * FROM skills WHERE skill_from_last_page = $skill";
  5. while ($row[]=mysql_fetch_array($sql_result));
  6. //unset the blank that will be added
  7. unset($row[count($row)-1]);
  8.  
  9. //you indicated you are retrieving values on
  10. //the 'next page', which suggests you need to
  11. //pass the data in $row[] to the next page somehow
  12. //either via session:
  13.  
  14. //session_start();
  15. //$_SESSION['row']=$row;
  16.  
  17. //or write out the rows in hidden fields...
  18. //foreach($row as $k=>$v){
  19. //  echo '<input type="hidden" name="row['.$k.']" value="'.$v.'">'
  20. //}
  21.  
  22. //or use cookies, get scope, etc...
  23. ?>
  24.  
  25. <?php
  26. //second page
  27.  
  28. //you need to get the values from $row again
  29. //depending on how you passed it in...
  30. //i.e.
  31. //session_start();
  32. //if(isset($_SESSION['row'])){$row=$_SESSION['row'];}
  33. //or
  34. //if(isset($_POST['row'])){$row=$_POST['row'];}
  35. //etc...
  36.  
  37. //loop through each query
  38. foreach($row as $k=>$v){
  39.   $result[$k]=mysql_query("SELECT * FROM skills2 WHERE '$v' = $skill2");
  40.   $resultVal[$k]=mysql_fetch_array($result[$k]);
  41. }
  42.  
  43. //$resultVal should now contain what you want as an array of values...
  44.  
  45. ?>


Cheers,
Keith.

Reply With Quote
  #3  
Old August 2nd, 2002, 10:03 AM
AaaDee AaaDee is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Huddersfield, West Yorkshire, UK
Posts: 4 AaaDee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via Yahoo to AaaDee
RE: Different Values

cheers, i know its confusing.

On the first page i have nine rows PULLED/TAKEN from the database.

All called $skill

while ($row = mysql_fetch_array($sql_result))
{
$skill = $row["skill"];
}

So it gets how many rows in the database where the column header is skill!

Skill_001
Skill_002
Skill_003
Skill_004
Skill_005
Skill_006
Skill_007
Skill_008
Skill_009

The problem is because it is doing it by pulling it from the database, they ALL have ONE (1) value.

The next page

Select * from skill WHERE last_page_value = "$skill"

so they all have 1 value. It seems to be overwriting each row at a time and only passes over the last row, but i need ALL 9 if thats how many are in the database.

Hope this helps you understand more.

Thank you VERY Much.

Adam

Reply With Quote
  #4  
Old August 2nd, 2002, 02:58 PM
Taoism Taoism is offline
Contributing User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Winnipeg, MB, Canada
Posts: 81 Taoism User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 30 sec
Reputation Power: 2
RE: Different Values

Well, two things:

1) why are you doing a select * when you want values from one column?

If you modify your select to say
SELECT skill FROM <blah>
then the code I posted should work for you.

2) If you *must* use
SELECT *

Then change the variable $skill in page one in the while loop to $skill[] and follow the rest of what I posted, except that on the page two stuff I posted you will change any reference to $row into $skill

Cheers,
Keith.

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > Different Values


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway