Announcement

Collapse
No announcement yet.

PHP Script Help Needed.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • PHP Script Help Needed.

    PHP Code:
    <?php 
    $location 
    "localhost"
    $username "root"
    $password ""
    $database "dzcom"

    $conn mysql_connect("$location","$username","$password"); 
    if (!
    $conn) die ("Could not connect MySQL"); 
    mysql_select_db($database,$conn) or die ("Could not open database"); 

    ini_set('display_errors',0); 
    if ((isset(
    $_SESSION['menu'])) && (!isset($_GET['menu']))) { 
        
    $menu $_SESSION['menu']; 
    } elseif (isset(
    $_GET['menu'])) { 
        if (
    $_SESSION['menu'] == $_GET['menu']) { 
            if (
    $_SESSION['expand'] == 0) { 
                
    $expand 1
            } else { 
                
    $expand 0
            } 
        } else { 
            
    $expand 1
        } 
        
    $_SESSION['expand'] = $expand
        
    $tmenu $_GET['menu']; 
        list(
    $menu,$trash) = explode("?",$tmenu,2); 
        
    $_SESSION['menu'] = $menu

    $expand $_SESSION['expand']; 
    list(
    $earl,$trash) = explode("?",$_SERVER['REQUEST_URI'],2); 
    ?> 
    <TABLE CELLSPACING="0" CELLPADDING="0" BORDER="0"> 
        <TR><TD><A CLASS="menu" HREF="<?php print($earl); ?>?menu=aaa">xPixel Home</A></TD></TR> 
        <?php if (($_SESSION['menu'] == "aaa") && ($expand)) { ?> 
        <TR><TD> 
            <TABLE CELLSPACING="0" CELLPADDING="0" BORDER="0"> 
                <TR><TD>
       <A HREF="<? 
       $query 
    "SELECT pageurl FROM pages"
    query($query); 
    $numrows mysql_num_rows($result); 
    while(
    $row mysql_fetch_array($result)){ 
     echo 
    "$row[pageurl]";
         }
    ?>">Page</a>
         </TD></TR> 
                
       <TR><TD><A HREF="index.php?id=test">Page
      </A></TD></TR> 
       <TR><TD><A HREF="index.php?id=about">About xPixel</A></TD></TR> 
                <TR><TD><A HREF="a3.php"><IMG SRC="menu2.php?text=A3" ALT="A3"></A></TD></TR> 
                <TR><TD><A HREF="a4.php"><IMG SRC="menu2.php?text=A4" ALT="A4"></A></TD></TR> 
                
            </TABLE></TD></TR><?php ?> 
        <TR><TD><A HREF="main.php?menu=home"><IMG SRC="menu.php?text=Home" ALT="Home"></A></TD></TR> 
    </TABLE> 
    <?php ini_set('display_errors',1); ?>
    That's the full code. The part I am having problems with is:
    PHP Code:
          <TR><TD>
       <A HREF="<? 
       $query 
    "SELECT pageurl FROM pages"
    $result mysql_query($query); 
    $numrows mysql_num_rows($result); 
    while(
    $row mysql_fetch_array($result)){ 
     echo 
    "$row[pageurl]";
         }
    ?>">Page</a>
         </TD></TR>
    I am trying to get it to display one row result from mySQL as the pageURL. But when I test it out, it shows all the rows .What do I have to do to fix it?

    Thanks,
    -Ant

  • #2
    Use:
    PHP Code:
    SELECT pagurl FROM pages LIMIT 1 
    for the query

    Comment


    • #3
      Thanks.

      How do I get it to display a different result per link?

      Comment


      • #4
        if I understand you correctly you would use
        PHP Code:
        rand(pageurl) as rand 
        in your query then
        PHP Code:
        ORDER BY rand 

        Comment


        • #5
          alrighty, I'll see how it works.

          Comment

          widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
          Working...
          X