-
Posts
310 -
Joined
-
Last visited
Never
Everything posted by Alexhoward
-
Probably very basic - php redirection error
Alexhoward replied to jpress07's topic in PHP Coding Help
Hi, your header code looks fine. try taking out the php. it looks like it's seeing it all as one line so, <? header( 'Location: http://my-affiliate-offer-link.com' ) ; ?> -
[SOLVED] Dropdown from mysql - retaining values
Alexhoward replied to Alexhoward's topic in PHP Coding Help
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>'; ?> -
[SOLVED] Dropdown from mysql - retaining values
Alexhoward replied to Alexhoward's topic in PHP Coding Help
Alright Guys, Right lets take this one step at a time... Does anyone know how to retain values in a drop down populated from mysql...? don;t worry about teh previous post about then using that value to populate another. all i want to do is have what ever is selected e.g. http://website.php?cat=electronics to then be selected when the page refreshes... Thanks in advance -
[SOLVED] Dropdown from mysql - retaining values
Alexhoward replied to Alexhoward's topic in PHP Coding Help
hi, thanks for all the help so far, but does anyone know how to do this...? cheers -
[SOLVED] Dropdown from mysql - retaining values
Alexhoward replied to Alexhoward's topic in PHP Coding Help
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? -
[SOLVED] Dropdown from mysql - retaining values
Alexhoward replied to Alexhoward's topic in PHP Coding Help
Hi, just to start this up again. Does anyone know how to reatin values in a dropdown populated from mysql..? -
[SOLVED] Dropdown from mysql - retaining values
Alexhoward replied to Alexhoward's topic in PHP Coding Help
Alright, smart! no quite what i'm after still thou...? think i can get it form here thou, but do you know how to get it to retain the selected value...? -
[SOLVED] Dropdown from mysql - retaining values
Alexhoward replied to Alexhoward's topic in PHP Coding Help
Hi, Thanks for spending the time to look at this... there's a lot of else's could you be more specific...? sorry for being a noob -
[SOLVED] Dropdown from mysql - retaining values
Alexhoward replied to Alexhoward's topic in PHP Coding Help
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 -
[SOLVED] Dropdown from mysql - retaining values
Alexhoward replied to Alexhoward's topic in PHP Coding Help
Thanks a lot! it was kind of working, but isn't now i'll keep playing and report back Cheers -
[SOLVED] Dropdown from mysql - retaining values
Alexhoward replied to Alexhoward's topic in PHP Coding Help
Hi, no, just one table category: cat | subcat -
[SOLVED] Dropdown from mysql - retaining values
Alexhoward replied to Alexhoward's topic in PHP Coding Help
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 -
[SOLVED] Dropdown from mysql - retaining values
Alexhoward replied to Alexhoward's topic in PHP Coding Help
wow! what a speedy reply! i'm not sure what you mean by that, i'll have a look on google cheers -
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!
-
[SOLVED] Explode day, month, year from mysql date
Alexhoward replied to Alexhoward's topic in PHP Coding Help
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 -
[SOLVED] Explode day, month, year from mysql date
Alexhoward replied to Alexhoward's topic in PHP Coding Help
it appears that it's not actually bringing anything back. yet if i do the same query in phpmyadmin, it works....? -
[SOLVED] Explode day, month, year from mysql date
Alexhoward replied to Alexhoward's topic in PHP Coding Help
Hi Andy, because when i do that i get the errors as above... also, i have just been testing the code, and it appears that is does not work correctly...? Thanks for taking the time to look at this -
[SOLVED] Explode day, month, year from mysql date
Alexhoward replied to Alexhoward's topic in PHP Coding Help
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")); ?> -
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,
-
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
-
Hi guys, hoping someone here might have an idea about this one... I looked around the internet but can't find a soulution... Basically does anyone know how to set a default value to a select drop down box? Thanks in advance
-
[SOLVED] Simple way to Export MYSQL table to excel...
Alexhoward replied to Alexhoward's topic in PHP Coding Help
Alright! I've sorted it! basically you can't have "ID" in cell 'A1' Thanks for all your help with this everyone! And, thanks for the code freakus_maximus! Nice one!! -
[SOLVED] Simple way to Export MYSQL table to excel...
Alexhoward replied to Alexhoward's topic in PHP Coding Help
Excellent, Thanks! This seems to do the job on recent browsers, but old ones are stuggling, or not exporting at all. Also, excel is getting the error "Unknown format - SYLK file" On recent excels you just press ok and it works anyway, but on older ones it won't. Do you know what's causing this? Thanks again -
[SOLVED] Simple way to Export MYSQL table to excel...
Alexhoward replied to Alexhoward's topic in PHP Coding Help
Cheers Litebearer, That pulls out all the data into csv, and displays it in html. What i'm really after is to download it into an excel file? is this possible? -
Hi Guys, This site has been a massive help so far, Thanks very much I was wondering if any one knew a simple way to export a MYSQL table to an excel file using a PHP script? Thanks in advance