PHP - Create A List Php/mysql
Similar TutorialsI have a mysql table with the structure of Code: [Select] ID Menu_Name Parent_ID 1 Finance NULL 2 Business NULL 3 Investment 1 4 Trading 2 How can I create a html <ul><li> list based on the parent? Hi, I have a chunk of text I am pulling from a mysql db like below. Air conditioning in rooms 24 Hour Reception Smoking rooms available How can I write this into - <ul> <li>Air conditioning in rooms</li> <li>24 Hour Reception</li> <li>Smoking rooms available</li> </ul> Many thanks. How to create Dependent Dropdown List?
<div class="form-group"> <label class="control-label col-sm-2" for="i_have">I have :</label> <div class="col-sm-10"> <select id="old" class="form-control" placeholder="Select I have" name="i_have"> <option value = "select_option">Select Option</option> <option value = "three_compact">3 Compact</option> <option value = "three_regular">3 Regular</option> <option value = "three_triple">3 Triple</option> <option value = "five_compact">5 Compact</option> <option value = "five_regular">5 Regular</option> <option value = "five_triple">5 Triple</option> <option value = "seven_compact">7 Compact</option> <option value = "seven_regular">7 Regular</option> <option value = "seven_triple">7 Triple</option> <option value = "nine_compact">9 Compact</option> <option value = "nine_regular">9 Regular</option> <option value = "nine_triple">9 Triple</option> </select> </div> </div> <div class="form-group"> <label class="control-label col-sm-2" for="i_want">I want :</label> <div class="col-sm-10"> <select id="new" class="form-control" placeholder="Select I want" name="i_want"> <option value = "select_option">Select Option</option> <option value = "three_compact">3 Compact</option> <option value = "three_regular">3 Regular</option> <option value = "three_triple">3 Triple</option> <option value = "five_compact">5 Compact</option> <option value = "five_regular">5 Regular</option> <option value = "five_triple">5 Triple</option> <option value = "seven_compact">7 Compact</option> <option value = "seven_regular">7 Regular</option> <option value = "seven_triple">7 Triple</option> <option value = "nine_compact">9 Compact</option> <option value = "nine_regular">9 Regular</option> <option value = "nine_triple">9 Triple</option> </select> </div> </div>
If the first dropdown "3 Compact " is selected second dropdown should not be able to select "3 Compact" & if first dropdown "5 Regular" is selected second dropdown should not be able to select below values of 5 Regular like "3 Compact, 3 Regular, 3 Triple, 5 Compact. The logic is, if first dropdown value selects like 5, second dropdown value must select above 5 not 4 or 3 or 2 or 1. I have the following code which works (thanks to PHP Freaks members)
foreach ($swap["sims"] as $swap) { echo $swap['voice'] . "</br>"; }But I can't figure out why the following doesn't work <select name="sim_for_swap[]"> <?php foreach ($swap["sims"] as $swap) { ?> <option value="<?php echo $swap['voice'];?>"><?php echo $swap['voice'];?></option> <?php } ?> i have made a simple header page for a project.
now i want to create a dropdown menu for a single menu item in the menu bar.
how i will do that ..??
for ex-under COURSES MENU, THE SUBMENU ARE : DEGREE,DIPLOMA,HIGHSCHOOL.
I am wanting to create a basic product listing page for a product category called "Belts". My latest attempt was this, but I got an error: PHP Code: Code: [Select] $query = "select * from products"; $result = mysql_query($query); while($row=mysql_fetch_assoc($result)) { print ".$row['name'] where category = 'Belts'.$row['colour'] where category = 'Belts'"; } Quote PHP Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING This is what my MySQL table looks like: http://i54.tinypic.com/2j1si8w.png I image what I am trying to do will print "Somename Black, ProductName2 Brown"? I'm not really interested in styling at the moment, I just want to see the PHP-MySQL work at the most basic level. I am unsure what the error cosde means. Can anyone see a fault in my code? Hi. I will try and explain simply.
I have a list of item codes eg.
size1 Acolor1
size1 Bcolor3
size1 Bcolor1
size1 Acolor3
size1 Acolor4
size2 Acolor1
size3 Bcolor1
size3 Bcolor2
size3 Bcolor2
size3 Acolor1
I want to take these and split them into parts:
size1 Acolor2
size1 Bcolor3
etc.
Then I want to create a form with 2 dropdowns. The first option would just have all unique sizes so:
size1
size2
size3
Then when one is selected, option 2 would show the colours available in that size.
Is there a standard way of doing this? Can I use PHP to create the array and then jquery to display and hide the options?
I'm totally stuck and i'm not just looking for somebody to code it all for me. any help would be greatly appreciated
thanks
Sam
i want to create array from mysql what is the script for this...? value like $data = array("1" => .0032, "2" => .0028, "3" => .0021, "4" => .0033, "5" => .0034, "6" => .0031, "7" => .0036, "8" => .0027, "9" => .0024, "10" => .0021, "11" => .0026, "12" => .0024, "13" => .0036, "14" => .0028, "15" => .0025); Hello guys, Hey guys, Currently Im using the code: while($row=mysql_fetch_array($nt)){ echo" $row[user_login],$row[user_email],$row[CallHistoryTimes],$row[CallHistoryInfo],$row[CallHistoryLastOp]$row[CallHistoryLastDate],<br>"; } To list a mysql array; what I am trying to do is to use the mysql row ID and turn the entire string above into a list. So for example, the database would get the ID information & create a link of edit.php/?id=3 If someone could help me on this it would be mega appreciated. Thanks i have two tables, employee details table(empno, emp_name , branch) and attendance table(date, Ot, attendence). I want to create a relation between two tables Hey yall! I'm working on a new site idea and I've run across a problem that I know is simple enough but I'm stumped. It's in the signup form What I want to do is insert the new user into the 'Login' table and get the user id that was just created and use that to create a table with the user id in the name. Here is what I have: // now we insert user into 'Login' table mysql_real_escape_string($insert = "INSERT INTO `Login` (`UID`, `pass`, `HR`, `mail`, `FullName`) VALUES ('{$_POST['username']}', '{$_POST['pass']}', '{$_POST['pass2']}', '{$_POST['e-mail']}', '{$_POST['FullName']}')"); mysql_query($insert) or die( 'Query string: ' . $insert . '<br />Produced an error: ' . mysql_error() . '<br />' ); $error="Thank you, you have been registered."; setcookie('Errors', $error, time()+20); // Get user ID mysql_real_escape_string($checkID = "SELECT * FROM Login WHERE `mail` = '{$_POST['e-mail']}'"); while ($checkIDdata = mysql_fetch_assoc($checkID)) { $userID = $checkIDdata; // now we create table 'Transactions" for the user mysql_real_escape_string($create = "CREATE TABLE `financewatsonn`.`Transactions_{$userID}` ( `ID` INT( 20 ) NOT NULL AUTO_INCREMENT COMMENT 'Transaction ID', `name` VARCHAR( 50 ) NOT NULL COMMENT 'Name/Location', `amount` VARCHAR( 50 ) NOT NULL COMMENT 'Amount', `date` VARCHAR( 50 ) NOT NULL COMMENT 'Date', `category` VARCHAR( 50 ) DEFAULT NULL COMMENT 'Category', `delete` INT( 1 ) NOT NULL DEFAULT '0', UNIQUE KEY `ID` ( `ID` ) ) ENGINE = MYISAM DEFAULT CHARSET = utf8 COMMENT = 'User ID {$userID}'"); mysql_query($create) or die( 'Query string: ' . $create . '<br />Produced an error: ' . mysql_error() . '<br />' ); } I know in 'Get user ID' that I need to get the ID but I'm not sure how to get that information. i get the error Quote Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource at 166 which is the while line under Get user ID I want to create a text file based blog ( not using MySQL or other databases). I have tried to google for tutorials but I couldn't find anything. is there anyone who can help me and give me some tips? is there any tutorials about this because I found nothing? Any good books? This is an assignment that I have to do and I am using this book: Spring into PHP 5 by Addison Wesley. I am a newbie in php and really want to do this because this is my last task and I really want to learn. So I'm grateful if anyone can help me. What I mean by dynamic is say I created a function to generate a random code. I put it in a variable named $key. I make a form with a hidden input type with the name and value of $key. When the form posts, it generates the table name to whatever $key is. Because I tried something like this & its not querying. Heres my code: <?php $dbc = mysqli_connect('localhost', 'cpacrop_todo', 'pass', 'cpacrop_todo') or die('Failed to connect to database!'); function make_key($num_chars) { if ((is_numeric($num_chars)) && ($num_chars > 0) && (! is_null($num_chars))) { $key = ''; $accepted_chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'; //seed srand(((int)((double)microtime()*1000003)) ); for ($i=0; $i<=$num_chars; $i++) { $random_number = rand(0, (strlen($accepted_chars) -1)); $key .= $accepted_chars[$random_number] ; } return $key; } } $key = make_key(6); ?> <form action="" method="post"> <input type="hidden" name="<?php echo "$key"; ?>" /> <input type="submit" name="submit" value="Submit" /> </form> <?php if ($_POST['submit'] == "Submit") { $query = "CREATE TABLE `$key` ( `id` INT AUTO_INCREMENT, `title` VARCHAR(35), `description` VARCHAR(365) );"; mysqli_query($dbc,$query) or die('Unable to query database.'); echo "Success"; } ?> If this is possible, what am I doing wrong? Thanks! I would like some tips on how to create a monthly archive for my weblog. I am not using MySQL or any databases. Everything is saved on file. any tips or tutorials? Thanks Hi there, I hope somebody can help me creating a loop for the following code: What it currently does is, showing only 1 image, while in fact there are 3 of them. I've combined a loginsystem with slideviewer. When i use the original php code (or a part of it) it only shows one listing. I need it to list all of them. <div id="mygalone" class="svw"> <ul> <li> <?php $result = mysql_query("SELECT reference FROM user_photos WHERE`profile_id`='".$row['id']."'"); while ($row2 = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "<a href=\"".$_GET['username']."/pics/".$row2['reference']."\"> <img src=\"".$_GET['username']."/pics/thumbs/".$row2['reference']."\"></a><br/><br/>"; } } ?> </li> </div> What can be stripped down to this: <?php { $result = mysql_query("SELECT reference FROM user_photos WHERE`profile_id`='".$row['id']."'"); while ($row2 = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "<img src=\"".$_GET['username']."/pics/".$row2['reference']."\">"; } } ?> You would asume that this is allready a loop, but it does not act like it. Best regards, Martijn (the netherlands) Hi to everybody I need ur help because I’m trying to make a script in php to write the same data but with different date in MySQL depending on the splitting ($data06).... like a schedule...
For example if $data06 = annual and $data03 = “2019/01/01” programm must create in MySQL : 2019/01/01 2020/01/01 2021/01/01 2022/01/01 2023/01/01
if $data06=“half year” will create 10 date , increasing 6 moths ...
But I have a problem at finish of code switch ($data06) { case 'annual': $numrate = 5; $aumdata = "+12 months"; break; case 'half year': $numrate = 10; $aumdata = "+6 month"; break;
default: echo "error"; $sql = "INSERT into $nometb ( name, scadenza ) values ( '$data01', '$data03' )"; if ($conna->query($sql) === TRUE) {} else {die('ERROR'. $conna->error); }
//IMPORT NEXT AND NEW DATE $newDate = date_create($data03); for ($mul = 2; $mul <= $numrate; ++$mul) {
$datanuova = date_create($data03); $datanuova->modify($aumdata); $datanuova->format('yy/m/d'); $newDate = $datanuova->format('yy/m/d');
$sql = "INSERT into $nometb ( name, scadenza ) values ( '$data01', '$newDate' )"; if ($conna->query($sql) === TRUE) {} else {die('ERROR'. $conna->error); }
//HERE THERE IS ERROR $data03 = $newDate;
if ($conna->query($sql) === TRUE) {} else {die('ERRORE NELL\'IMPORTAZIONE'. $conna->error); } }
} }
}
How I can resolve ?
many thanks Francesco I've just learned the basics of MySQL last night and made a simple app (where a user enters a song name, song title, and rating (out of 5) and it displays the list of songs with the highest rated songs first). So I decided I wanted to make something similar yet slightly more complicated and I'm not sure if I'm on the right track. Basically it's a "flash card" game whe - The user gets to input their own questions and answers into a simple form, which would then go into an MySQL table with 2 columns, questions and answers - A new page where the user see's random question, must input an answer, if the answer matches goes to next question otherwise gives error Now I'm confused as to how to go about making this. I was thinking of making some session variables and then do something along the lines of Code: [Select] $display_query = "SELECT * FROM questions"; $display = mysqli_query($connection, $display_query); while ($row = mysqli_fetch_array($display)) { $_SESSION['question'] = $row[0]; }[/syntax] //and then make some PHP that might do something like this: if ($_SESSION['answer'] != $row[1]) { echo "error, try again" } else { // I would write something here to grab the next question } So am I just completely off the wall with this, how would I make such an app? How would I make it, for example, fetch new questions? Hello
I have a mysql table like this:
id | user | car 1 | 1 | fiat 500 2 | 2 | vw polo 3 | 2 | vw golf 4 | 3 | renault clio 5 | 2 | fiat panda 6 | 3 | seat ibiza From this table how can i get a query that the result be like: user 2 - 3 cars user 3 - 2 cars user 1 - 1 cars Thanks How would I create a prepared mysql temp table using PHP? I currently write my prepared statements like the example below. How would I create a "TEMP" table? Thanks!
$connection8y = new mysqli("host", "xxx", "xxx", "db"); |