Jump to content

moderith

New Members
  • Posts

    7
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

moderith's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. thanks everyone. Yah seems like foreach is the way to go.
  2. I understand that. How about this, is there a way I can see the coding behind a function like mysql_fetch_assoc?
  3. Thanks for replying guys I appreciate it. I feel that more explanation is in order though. Your absolutely right I can do it that way and is how I have been doing it. Though I am still warping a foreach loop in a foreach loop, and my question still remains. I'm sorry but it is rather hard for me to put this question into words as it is kinda complicated in my own mind. So I will ask this instead. How is it that a mysql_fetch_assoc() works? why is it that I can have a 1000 rows of data from a query but still call them with the same array name ($row["name"]) in a while loop? $result = mysql_query("SELECT name FROM users"); if($row = mysql_fetch_assoc($result)){ echo $row["name"].'<br />'; } How do I take 1000 entries in an array and make them all spit out in a while loop by only using ($row["name"]) and not $row[1]["name"], $row[2]["name"], $row[3]["name"], $row[4]["name"] and so on? BTW how are you guys posting the code in a colored format that is cool I am putting the [ code ][ /code ] tags around it but don't get that.
  4. mabey with a foreach loop? foreach($a as $b){ echo $b; }
  5. Hello World! I do hate going to a new forum and asking a question first thing, so I did help solve a problem first. Okay so lets say you have a multi-dimensional array, $row[1]["name"] = 'fred'; $row[1]["age"] = '25'; $row[1]["sex"] = 'male'; $row[2]["name"] = 'jack'; $row[2]["age"] = '42'; $row[2]["sex"] = 'male'; $row[3]["name"] = 'kerry'; $row[3]["age"] = '19'; $row[3]["sex"] = 'female'; and you want to spit out all that information in a loop. for($i=1;$i<=3;$i++){ echo 'Name: '.$row[$i]["name"].' | Age:'.$row[$i]["age"].' | Sex: '.$row[$i]["sex"].'<br />'; } Great, but wait a minute, there has to be a better way of doing this. I have seen it done with a mysql_fetch_assoc(). $result = mysql_query("SELECT * FROM users"); while($row = mysql_fetch_assoc($result)){ echo 'Name: '.$row["name"].' | Age:'.$row["age"].' | Sex: '.$row["sex"].'<br />'; } How did they do that? I mean there are multiple rows but I don't have to use $row[$i]["name"] I can just use $row["name"]. Is there a way I can turn my multi-dimensional array into something that I can execute with a while loop? Thanks in advance.
  6. you have name="a3" name="a1" why are you naming twice?
  7. Hi, Samoht Heres what I would do. $url = 'http://www.mysite.com//'; $newurl = substr($url, 0, -1); echo $newurl; //http://www.mysite.com/ Happy Coding
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.