Dynadot โ€” .com Transfer

Easy MySQL + Array with PHP question

SpaceshipSpaceship
Watch

matrocka

Established Member
Impact
0
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!
 
Last edited:
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
Unstoppable Domains โ€” AI StorefrontUnstoppable Domains โ€” AI Storefront
Hmm im slightly confused.

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

Instead be:

PHP:
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 :p
 
Last edited:
0
•••
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>
 
0
•••
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>";
 
0
•••
CatchedCatched
Escrow.com
Spaceship
Rexus Domain
CryptoExchange.com
Domain Recover
CatchDoms
DomDB
NameFit
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back