SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2008
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Concatenate 2 Arrays

    Why isn't this working?

    Code:
    include "dconnection.php";
    $sql1=mysql_query("Select num1,num2 FROM Numbers");
    $n=mysql_numrows($sql1);
    $i=0;
    while($i<$n)
    {
    	$larr[$i]=mysql_result($sql1,$i,"num1");
    	$rarr[$i]=mysql_result($sql1,$i,"num2");
    	$pair[$i]=$larr[$i].'/'.$rarr[i];
    	echo "$pair[$i]\n";
    	$i++;
    }
    This just echos the first array with the slash. Why isn't the conctenation working?

    Thanks

  2. #2
    SitePoint Zealot
    Join Date
    Oct 2008
    Posts
    167
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Should probably be:

    PHP Code:
    $pair[$i]=$larr[$i].'/'.$rarr[$i]; 
    instead of:

    PHP Code:
    $pair[$i]=$larr[$i].'/'.$rarr[i]; 
    (no $ on the i variable for $rarr array)

    Outside of that, are you sure that $rarr[$i] has a value?
    CanisHosting - Web Hosting plans starting at $3.95 per month

  3. #3
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $sql1=mysql_query("Select CONCAT(num1, '/', num2) AS Pair FROM Numbers");

  4. #4
    SitePoint Enthusiast
    Join Date
    Aug 2008
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you. Sorry for not replying... got hit by the flu.

    Anyway sparek was right..put in the $ sign and everything worked great.

    Thanks.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •