[advanced search]
Results from the most recent live auction are here.
22 members in the live chat room. Join Chat!
Register Rules & FAQ NP$ Store Active Threads Mark Forums Read
Domain Name Industry Newsletter
Go Back   NamePros.Com > Design and Development > Programming
User Name
Password

Old 11-13-2006, 12:32 PM   · #1
matrocka
NamePros Member
 
Trader Rating: (3)
Join Date: Jun 2006
Posts: 92
NP$: 183.00 (Donate)
matrocka is an unknown quantity at this point
Easy MySQL + Array with PHP question

while ($line = @mysql_fetch_array($result)) {
$X=$line['lastname'];
$Y=$line['lastnameid'];

$namesreturned[$Y]="<p>$X</p>";
}


how do i reference the numerical value (the $Y) in the code?

i.e. if i want to do the following:

$amount=count($namesreturned);
if ($amount==0){echo "<p>nothing to return!</p>";}
else {echo "<h2>There are $numr results listed below: </h2>";
$z=0;
while ($z<=$amount){
echo "<a href=\"http://www.xxx.com/index.php?name=$Y\">".$namesreturned[$z]."</a>";
$x++;
}

(reference the ((Key)) $Y)

Thanks!


Please register or log-in into NamePros to hide ads
__________________
Surname-Index.com - How common is your last name?

Last edited by matrocka : 11-13-2006 at 12:47 PM.
matrocka is offline   Reply With Quote
Old 11-13-2006, 01:47 PM   · #2
beaver6813
NamePros Regular
 
beaver6813's Avatar
 
Name: Sam Cleaver
Location: England
Trader Rating: (11)
Join Date: May 2005
Posts: 346
NP$: 59.50 (Donate)
beaver6813 is a jewel in the roughbeaver6813 is a jewel in the roughbeaver6813 is a jewel in the rough
Hmm im slightly confused.

From what i can see would the:
PHP Code:
echo "<a href=\"http://www.xxx.com/index.php?name=$Y\">".$namesreturned[$z]."</a>";


Instead be:

PHP Code:
echo "<a href=\"http://www.xxx.com/index.php?name=$z\">".$namesreturned[$z]."</a>";


As you are echoing the value using $namesreturned[$z] and then the key for this would be $z.

Explain more clearly
__________________
-Beaver6813.com V5 Soon!

Last edited by beaver6813 : 11-13-2006 at 02:08 PM.
beaver6813 is offline   Reply With Quote
Old 11-13-2006, 06:56 PM   · #3
Dan
Buy my domains.
 
Dan's Avatar
 
Name: Dan
Trader Rating: (63)
Join Date: Feb 2006
Posts: 2,801
NP$: 54.00 (Donate)
Dan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant future
Autism Autism Autism Autism Autism Autism Autism
Change
Code:
while ($z<=$amount){ echo "<a href=\"http://www.xxx.com/index.php?name=$Y\">".$namesreturned[$z]."</a>"; $x++; }

To
Code:
foreach ($namesreturned as $y => $x){ echo "<a href=\"http://www.xxx.com/index.php?name=$y\">".$x."</a>"; }



I don't know if that's what you wanted or not, but now $y is the id and $x is <p>whatever</p>
Dan is offline   Reply With Quote
Old 11-14-2006, 12:47 AM   · #4
kzaid1
New Member
 
Trader Rating: (0)
Join Date: Jul 2006
Posts: 16
NP$: 0.00 (Donate)
kzaid1 is an unknown quantity at this point
why don't you use the foreach or for
like this

for($z=0;$z<=$amount;$z++)
echo "<a href=\"http://www.xxx.com/index.php?name={$z}\">{$namesreturned[$z]}</a>";

or

foreach($namesreturned as $y => $x)
echo "<a href=\"http://www.xxx.com/index.php?name={$y}\">{$x}</a>";
__________________
kzaid1 is offline   Reply With Quote
Closed Thread

NamePros is a revenue sharing forum.

Thread Tools

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


Site Sponsors
Website Header Design Hunting Moon Arcade Script
Advertise your business at NamePros
All times are GMT -7. The time now is 11:03 AM.


Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0