1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Some php help

Discussion in 'General Programming Chat' started by jake3340, Oct 22, 2010.

  1. jake3340

    jake3340 Jr. VIP Jr. VIP Premium Member

    Joined:
    Nov 20, 2008
    Messages:
    1,368
    Likes Received:
    414
    Location:
    Pluto
    Okay im a noob when it comes to php but i know a bit to get by. Okay so here is what I am trying to do. I created an sql database and inserted 10 links into it, I want to create a loop and echo the first link, when the loop, loops again it echos the second link after it reaches the end instead of starting over again it stops. How do i go around doing this ?
     
  2. Inter

    Inter Newbie

    Joined:
    Nov 2, 2010
    Messages:
    17
    Likes Received:
    2
    Not sure if I understand your question correctly but you want to create a website that takes a list of 10 links from a sql database and echo's the first one.... then you want it to echo the second link and so on until it reaches the end.
    What I can't wrap my head around is what you mean by the "loop" do you want it to echo all the links on 1 page with one page refresh or do you want it to refresh the page and spit out the next one... Basically what "loops" in order to get the next link?
     
  3. msimurin

    msimurin Regular Member

    Joined:
    Sep 21, 2009
    Messages:
    243
    Likes Received:
    92
    I am not much into php but i think this could be done simply by putting links into array

    PHP:
    [PHP]$arraylinks = array("http://site1.com""http://site2.com""http://site3.com""http://site4.com");
    then afterwards

    PHP:
    foreach ($arraylinks as &$value) {
        echo 
    $value; }
    So, this will echo every link in $arraylinks array, once

    I didnt have much experience about putting sql database content into array but i figure its not hard to google
     
    Last edited: Nov 6, 2010
  4. Asif Brown

    Asif Brown Newbie

    Joined:
    Oct 23, 2010
    Messages:
    2
    Likes Received:
    0
    If your problem not solved yet , I can help you.

    let me know in gtalk or gmail : asifbrown

    Thanks,
    Asif
    Sr. Software Engineer
     
  5. msimurin

    msimurin Regular Member

    Joined:
    Sep 21, 2009
    Messages:
    243
    Likes Received:
    92
    posts 1 and already ask for job? :)
     
  6. tutzor

    tutzor Registered Member

    Joined:
    Aug 13, 2008
    Messages:
    76
    Likes Received:
    9
    that's really easy:

    PHP:
    $db = new MySQLi($host$user$pass$db_name);
    $result $db->query("select $column_name from $your_table_name");
    while (
    $row $result->fetch_assoc()){
            print 
    $row[$column_name];
    }
    //gg
     
  7. artizhay

    artizhay BANNED BANNED

    Joined:
    Nov 21, 2010
    Messages:
    1,867
    Likes Received:
    1,335
    PHP:
    // get links from database
    $getLinks mysql_query("SELECT `link` FROM `links_table`");
    // create an array at the first row, echo that row, then continue to next row
    while ($linksArr mysql_fetch_array($getLinks)) echo $linksArr['link'] . "<br>";
     
    Last edited: Nov 22, 2010
  8. cyrix

    cyrix Junior Member

    Joined:
    Sep 19, 2008
    Messages:
    179
    Likes Received:
    61
    Occupation:
    Full Time Internet Marketer\Developer
    Location:
    United States
    This should do the trick

    PHP:
    <?php
        
    if ($con mysql_connect('host''user''password')) {
            if (
    mysql_select_db) {
                
    $result mysql_query('SELECT * FROM `table`');
                
                if (
    mysql_num_rows($result) > 0) {
                    while(
    $row mysql_fetch_assoc($result)) {
                        echo 
    $row['field name'];
                    }
                } else {
                    die(
    'No records returned.');
                }
            } else {
                die(
    'Unable to select MySql Database.');
            }
        } else {
            die(
    'Unable to connect to MySQL Server.');
        }
    ?>