Jump to content

marcus

Members
  • Posts

    1,842
  • Joined

  • Last visited

Posts posted by marcus

  1. Well the best to make a drop down is like:

    [code]
    <?php
    $sql = "SELECT * FROM table";
    $res = mysql_query($sql);
    echo "Width: <select name=width>\n";
    while($row = mysql_fetch_assoc($res)){
    echo "<option value=$row[width]>$row[width] Inches</option>\n";
    }
    echo "</select>";
    echo "Height: <select name=height>\n";
    while($row = mysql_fetch_assoc($res)){
    echo "<option value=$row[height]>$row[height] Inches</option>\n";
    }
    echo "</select>";
    ?>
    [/code]
  2. [code]
    <?php
    $sql1 = "SELECT * FROM `width` WHERE `width` < 5";
    $res1 = mysql_query($sql1);
    echo "<select name=width>";
    while($row1 = mysql_fetch_assoc($res1)){
    echo "<option value=$row1[width]>$row[width] inches</option>\n";
    }
    echo "</select>";
    $sql2 = "SELECT * FROM `height` WHERE `height` < 3";
    $res2 = mysql_query($sql2);
    echo "<select name=height>";
    while($row2 = mysql_fetch_assoc($res2)){
    echo "<option value=$row[height]>$row[height] inches</option>\n";
    }
    echo "</select>";
    ?>
    [/code]
  3. I'm making a restock system and the rows are not being inputted correctly.

    [code]
    <?php
    require('../connect.php');
    $min = date("i");

    $sql[time] = "SELECT `time` FROM `shops` WHERE `id` =1";
    $res[time] = mysql_query($sql[time]);
    $rowtime = mysql_fetch_assoc($res[time]);

    if($min == $rowtime[time]){
    //will have array of items
    //insert into time using BLAH
    //also update time, if $min > 10 new time will eqaul rand(11,20), if $min > 20, rand(21,30), etc....


    }else {
    //die();
    }

      $sql = "SELECT * FROM `list_items` WHERE `type` ='Food'";
      $res = mysql_query($sql) or die(mysql_error());
      $array = array();
      $arra2 = array();
      $arra3 = array();
      $arra4 = array();
      $total = mysql_num_rows($res);
      while ($row = mysql_fetch_assoc($res)) {
        $array[] = $row['ID'];
        $arra2[] = $row['item_name'];
        $arra3[] = $row['url'];
        $arra4[] = $row['estimate_price'];

      }
    foreach($array as $val) {
      $array = "$val,";
      echo "$array";


    }
    echo "<br>";
    foreach($arra2 as $val2){
      $arra2 = "$val2,";
      echo "$arra2";
    }
    echo "<br>";
    foreach($arra3 as $val3){
      $arra3 = "$val3,";
      echo "$arra3";
    }
    echo "<br>";
    foreach($arra4 as $val4){
      $arra4 = "$val4,";
      echo "$arra4";
    }
      $num = rand(1,$total);
      for ($i = 0;$i <= $num; $i++){
        if (mysql_query("INSERT INTO `shopstock` (`itemid`,`item_name`,`url`,`price`) VALUES ('$array[$i]','$arra2[$i]','$arra3[$i]','$arra4[$i]');")) {
          echo $array[$i]." inserted";
        }
      }

    ?>
    [/code]

    Basically I get:


    Full Texts id itemid item_name url price stock place
    Edit Delete 1 2 Y h 3 0
    Edit Delete 2 2 u t 0 0
    Edit Delete 3 5 c t 1 0
    Edit Delete 4 0 k p 0 0
    Edit Delete 5 0 y : 0 0
    Edit Delete 6 0   / 0 0
    Edit Delete 7 0 R / 0 0
    Edit Delete 8 0 i w 0 0
    Edit Delete 9 0 c w 0 0
    Edit Delete 10 0 e w 0 0
    Edit Delete 11 0 , . 0 0
    Edit Delete 12 0   t 0 0
    Edit Delete 13 0   e 0 0

    dont worry about place.
  4. [code]
    $sql = "SELECT * FROM `list_items` WHERE `type` ='Food'";
    $res = mysql_query($sql) or die(mysql_error());
    $array = array();
    while ($row = mysql_fetch_assoc($res)) {
      $array[] = $row['ID'];
    }
    foreach($array as $val) {
      $array = "$val,";
      echo $array;
    }
    [/code]

    Is what I'm trying to do is to have an array ($array) probably explode it, and then do a random number 1,20 and then take the random number and select that many items from the array, and insert them into the database.
  5. [code]
    <?php
    $sql = "SELECT * FROM `users`";
    $res = mysql_query($sql) or die(mysql_error());

    echo "<table border=0 cellspacing=3 cellpadding=2>\n";
    echo "<tr><td>ID<td>link 1<td>link 2\n";
    while($row = mysql_fetch_assoc($res)){
    echo '<tr><td>'.$row[id].'<td><a href="profile.php?id='.$row[id].'">$row[username]</a><td><a href="linktwo.php?id='.$row[id].'">$row[whatever]</a>\n";
    }
    echo "</table>";
    mysql_free_result($res);
    ?>
    [/code]
  6. That's pretty simple.

    If you use cookies:
    [code]
    <?php
    //stuff available to everyone here

    if(isset($_COOKIE['logged'])){
    //add my account logged in only stuff here
    }
    ?>
    [/code]

    For sessions:
    [code]
    <?php
    //stuff available to everyone here
    if(isset($_SESSION['logged'])){
    //add my account logged in only stuff here
    }
    ?>
    [/code]

    Just changed logged to whatever your cookie or session is called when the user logs in.
  7. You can do some if functions with a get variable.

    [code]
    <?php
    $id = $_GET['id'];
    //id will be a page in the folder inc, $id.inc

    if(!isset($id)){
    include('inc/index.inc');
    }else {

    if(!file_exists("inc/$id.inc")){
    echo "The page you are trying to view is not available";
    }else {
    include("inc/$id.inc");
    }
    }
    ?>
    [/code]
×
×
  • 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.