Jump to content

Alexhoward

Members
  • Posts

    310
  • Joined

  • Last visited

    Never

Posts posted by Alexhoward

  1. Sweet!

     

    This is how you do it!

     

    Thanks for everybodys help on this.

     

    Thanks to craygo who did give me the correct answer, but missed the variable in the echo, however i should have spotted that ages a go,

     

    Thanks again!

     

    <?php
    
    include("config.php");
    
    //connect to the mysql server
    $link = mysql_connect($host, $db, $pass)
    or die ("Could not connect to mysql because ".mysql_error());
    
    //select the database	
    mysql_select_db($db)
    or die ("Could not select database because ".mysql_error());
    
    
    echo'<form><select name="cat" style="width:160px;">';
    
    $res=mysql_query("select distinct cat from category order by cat");
    if(mysql_num_rows($res)==0) echo "there is no data in table..";
    else
    for($i=0;$i<mysql_num_rows($res);$i++) {
    $row=mysql_fetch_assoc($res);
    $selected = @$_GET['cat'] == $row['cat'] ? "selected" : "";
    echo"<option value=".$row['cat']." $selected>".$row['cat']."</option>";
    }
    echo'</select>';
    echo'<input type="submit" value="select"></form>';
    
    ?>
    

  2. Hi,

     

    Thanks for your reply

     

    I have my code set up like this

     

    <?php
    
    include("config.php");
    
    //connect to the mysql server
    $link = mysql_connect($host, $db, $pass)
    or die ("Could not connect to mysql because ".mysql_error());
    
    //select the database	
    mysql_select_db($db)
    or die ("Could not select database because ".mysql_error());
    
    
    echo'<form><select name="cat" style="width:130px;">';
    
    $res=mysql_query("select distinct cat from category order by cat");
    if(mysql_num_rows($res)==0) echo "there is no data in table..";
    else
    for($i=0;$i<mysql_num_rows($res);$i++) {
    $row=mysql_fetch_assoc($res);
    $selected = @$_POST['cat'] == $row['cat'] ? "selected" : "";
    echo"<option value=\"{$row['cat']}\" />{$row['cat']}</option>\n";
    }
    echo'</select>';
    echo'<input type="submit" value="select"></form>';
    
    ?>
    

     

    but it doesn't seem to be retaining the value...?

     

    have i done it correctly?

  3. Alright Cool,

     

    This code, brings up the category drop down, then when you select a value it replaces it with the sub-category dropdown.

     

    Then if you select a sub-category it changes back to select a category...

     

    this is nice, but what i'm really after is two dropdowns; category and subcategory, that retain their values once a selction is made, and the sub-category value is determined by the category value.

     

    I will then use the two values to filter the results

     

    Thanks for all your help so far

  4. umm...

     

    I think the problem is that my code is like this:

     

    <?php
    
    echo'<form><select name="cat" style="width:130px;">';
    
    $res=mysql_query("select distinct cat from category order by cat");
    if(mysql_num_rows($res)==0) echo "there is no data in table..";
    else
    for($i=0;$i<mysql_num_rows($res);$i++) {
    $row=mysql_fetch_assoc($res);
    echo"<option>$row[cat]</option>";
    }
    echo'</select><input type="submit" value="Select"></form>';
    
    ?>
    

     

    so there is only one physical option in the php

  5. Hi guys,

     

    I can't seem to work this out?

     

    can anyone help me?

     

    want i'm trying to do is select a category from a dropdown which is populated from mysql, then select a sub-category from another dropdown populated from mysql from that selection.

     

    i've got the mysql part down,

     

    However, i'm having trouble retaining the values...

     

    i don't really want to use javascript or anything...

     

    hoping someone can give me a simple answer

     

    Thanks in advance!

  6. Here's the answer.

     

    include("whatever.php");
    
    mysql_connect($host, $db, $pass)
    or die ("Could not connect to mysql because ".mysql_error());
    
    mysql_select_db($db)
    or die ("Could not select database because ".mysql_error());
    
    $mysite_username = $HTTP_COOKIE_VARS["sitename"]; 
    
    $year=mysql_query("SELECT dob FROM `profile` WHERE username = '$mysite_username'");
    while($year1 = mysql_fetch_array($year))
    $test = $year1['dob'];
    
    list($a, $v, $c) = explode('-',$test);
    
    echo $c
    

     

    yipee!

     

    i solved one :D

  7. Hi Andy,

     

    Thanks for the reply

     

    I got it going like this, which i assume works, but now it's only single digits,

     

    e.g: 0 instead of 00

     

    is there a way to make number_format double digits..?

     

    Thanks

     

    <?php
    $year=mysql_query("SELECT dob FROM $table WHERE username = '$mysite_username'");
    while($year1 = mysql_fetch_array($year))
    echo $year1['dob']; 
    
    echo number_format(date($year1,"dd"));
    
    ?>
    

  8. Hi guys,

     

    back again so soon, sorry.

     

    but i'm getting an error code from this piece for script that i don't understand: Undefined offset: 2

     

    and : Undefined offset: 1

     

    am i not doing this correctly...?

     

    <?php
    include("whatever.php");
    
    mysql_connect($host, $db, $pass)
    or die ("Could not connect to mysql because ".mysql_error());
    
    mysql_select_db($db)
    or die ("Could not select database because ".mysql_error());
    
    $mysite_username = $HTTP_COOKIE_VARS["sitename"]; 
    
    $year=mysql_query("SELECT dob FROM $table WHERE username = '$mysite_username'");
    while($year1 = mysql_fetch_array($year))
    $year1['dob']; 
    
    list ($y, $sm, $d) = explode ('-', $year1);
    
    echo number_format($d);
    
    ?>
    

     

    Thanks for all your help,

  9. Nice one!

     

    so if i just bang the php in there to grad a number from mysql, that's what it'll show!

     

    e.g.

     

    <option value="<?php  ?>" selected="selected"><?php ?></option>
    

     

    however, this would put the number in twice...?

     

    for example

     

    php "selected", 1,2,3,4,...

     

    but i can live with that!

     

    cheers

×
×
  • 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.