Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Dec 2008
    Posts
    129
    Thanks
    0
    Thanked 0 Times in 0 Posts

    variable problem

    the red color is the error

    i made an SQL statement that stores the id's in variable named by

    $addaddd1
    $addaddd2
    $addaddd3
    according to number of rows



    Code:
           $res_rows = mysql_num_rows($result3); // number of rows		
    	while ($jo = mysql_fetch_array($result3))
    					{
    						$a = "addaddd".$n;
    						$$a=$jo[0];
    						echo  ''.$addaddd5.'<br>';
    						$n+=1;
    					}
    the result is
    $addaddd1=1

    $addaddd2=3

    $addaddd3=7


    i want to use the variable addaddd in another statment to use a query where the id is equal to the variable so it will be cat_id=1
    the second cat_id=3 and the third cat_id=7


    Code:
    for ($i=1 ; $i <= $res_rows ; $i++ )
    					{	
    								
    						
    $qryp2 = "SELECT a.cat_id as cat_id ,  a.category as category , b.folder_path AS folder_path , b.categ_id as categ_id  , b.id as id , b.sub_category as sub_category  FROM category a , sub_category b  where a.cat_id= " . $addaddd.$i . " and a.cat_id = b.categ_id order by a.cat_id ASC";
    }

    i want the variable
    a.cat_id=$addaddd1

    a.cat_id=$addaddd3

    a.cat_id=$addaddd7



    so plz i need ur help

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Why would you not just use an array and reference an index in an array? Why do you require the variable name to be $addaddd appended with a number? Just use $addaddd[n], where 'n' is 1, 2, 3, etc.


  •  

    Posting Permissions

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