Ordonare una sub alta date preluate cu Select din MySQL

Discutii despre script-uri si coduri PHP-MySQL, precum si lucru cu XML in PHP.
tycyssg
Mesaje:58

Ordonare una sub alta date preluate cu Select din MySQL

Incep cu multumiri lui marplo pentru raspunsul la topicul anterior.

Am un formular care are 5 campuri.Unul din ele este de tip select , acest camp contine mai multe tipuri de telefoane.

Cod: Selectaţi tot

<table>
			<form method="post" action="addreparationsend.php" onsubmit="return checkForm(this);">
			<tr><td ><span class="centerphoness">Select Phone Model</span></td></tr>
			<tr><td ><select name="phonmodel" class="profilnamers">
			<option value="">Select carefully the phone model !</option>
			<option value="">&nbsp;</option>
			<option value="3g">Iphone 3G</option>
			<option value="3gs">Iphone 3GS</option>
			<option value="iph4">Iphone 4</option>
			<option value="iph4s">Iphone 4S</option>
			<option value="">&nbsp;</option>
			<option value="touch1">Ipod touch 1</option>
			<option value="touch2">Ipod touch 2</option>
			<option value="touch3">Ipod touch 3</option>
			<option value="touch4">Ipod touch 4</option>
			<option value="">&nbsp;</option>
			<option value="ipad2">Ipad 2</option>
			<option value="ipad3">Ipad 3</option>
			<option value="">&nbsp;</option>
			<option value="c6">Nokia C6</option>
			<option value="c7">Nokia C7</option>
			<option value="n8">Nokia N8</option>
			<option value="n9">Nokia N9</option>
			<option value="n95">Nokia N95</option>
			<option value="n97">Nokia N97</option>
			<option value="n98">Nokia N98</option>
			<option value="n900">Nokia N900</option>
			<option value="x5">Nokia X5</option>
			<option value="x6">Nokia X6</option>
			<option value="6700">Nokia 6700 Classic</option>
			<option value="6700s">Nokia 6700 Slide</option>
			<option value="">&nbsp;</option>
			<option value="desire">HTC Desire</option>
			<option value="desires">HTC Desire S</option>
			<option value="wild">HTC Wildfire</option>
		    <option value="wilds">HTC WIldfire S</option>
			<option value="sensation">HTC Sensation</option>
			<option value="sensationxl">HTC Sensation XL</option>
			<option value="">&nbsp;</option>
			<option value="b8520">BlackBerry 8520</option>
			<option value="b9000">BlackBerry 9000</option>
			<option value="b9300">BlackBerry 9300</option>
			<option value="b9650">BlackBerry 9650</option>
			<option value="b9700">BlackBerry 9700</option>
			<option value="b9780">BlackBerry 9780</option>
			<option value="b9800">BlackBerry 9800</option>
			<option value="b9810">BlackBerry 9810</option>
			<option value="b9900">BlackBerry 9900</option>
			<option value="b9930">BlackBerry 9930</option>
			<option value="">&nbsp;</option>
			<option value="laptops">Laptops</option>
			</select>
			</td></tr>
			<tr><td ><span class="centerphoness">Name Reparation</span></td></tr>
			<tr><td ><input type="text" name="namerep" id="namerep" value="" class="profilnamer" ></td></tr>
			<tr><td><span class="centerphoness">Daily Message</span></td></tr>
			<tr><td><input type="text" name="daylimsj" value="We will try to complete this repair same day for you!" class="profilnamer"></td></tr>
			<tr><td ><span class="centerphoness">Price</span></td></tr>
			<tr><td><input type="text" name="price" id="price" value="" class="profilname"></td>
			<tr><td ><span class="centerphoness">Reparation Description</span></td></tr>
			<tr><td><textarea class="profilnamer" name="desreparation" id="desreparation" rows="7" cols="22">Describe reparation</textarea></td></tr>
			<tr><td><br /><input type="submit" name="addreparation" value="Add Reparation" id="profname"></td></form></tr>
			</table>
Acesta e formularul. Bun , introduc in baza de date viitoarele date prin scriptul:

Cod: Selectaţi tot

<?php
    if($_SESSION['logat'] != 'Da') {
echo '
<div class="useus">Warning! To acces this page you need to be logged.</div>
';
}
else {
if(isset($_POST['phonmodel']) && isset($_POST['namerep']) && isset($_POST['daylimsj']) && isset($_POST['price']) && isset($_POST['desreparation'])){
   mysql_select_db("autentificare", $conexiune);
$sql="INSERT INTO reparation (phonemodel,namerep,daylimsj,price,desreparation)
VALUES
('".$_POST['phonmodel']."',
'".$_POST['namerep']."',
'".$_POST['daylimsj']."',
'".$_POST['price']."',
'".$_POST['desreparation']."'
)";

if (!mysql_query($sql,$conexiune)){
  die('Error: ' . mysql_error());
}
echo '
<center><div class="centerphones">Congratulation <b><i>'.$_SESSION['user'].'</b></i></div></center>
<div class="useus"> The reparation has been added</div>
 ';
}
mysql_close($conexiune);
}
?>
Si le scot printr-un select:

Cod: Selectaţi tot

<?php
mysql_select_db("autentificare", $conexiune);

$result=mysql_query("SELECT *FROM orders WHERE phonemodel=3gs);
while($row = mysql_fetch_array($result)) {
  echo'.$row['namerep'].$row['daylimsj'].$row['price'].$row['desreparation'].';
}

mysql_close($conexiune);
?>
Acum incep problemele mele. Deci completez formularul cu datele necesare. Aleg modelul de tel sa zicem 3gs adica Iphone 3gs , scriu numele la reparatie , pretul , descrierea; si trimit in baza de date. Dupa cum observi selectez randul care contine valoarea 3gs. Scriptul asta va fi intr-o pagina care va contine toate reparatiile pentru acest tip de telefon.

Ceea ce vreau este, numai in cazul in care se poate, ca la adoua reparatie pe care o adaug pentru modelul asta sa se afiseze dedesupt si prima sa ramana si ea afisata, ca si cum s-ar forma o lista de reparatii, ori de cate ori adaug o reparatie sa se adauge dedesupt.

Cred ca se poate rezolva cu un "for()" dar sunt incepator in asta si nu prea stiu cum sa il implementez. Daca m-ar putea ajuta cineva as ramane recunoscator.

MarPlo Mesaje:4343
Salut
Instructiunea while() dupa Select:

Cod: Selectaţi tot

$result = mysql_query("SELECT * FROM orders WHERE phonemodel=3gs);
while($row = mysql_fetch_array($result)) {
  echo'.$row['namerep'].$row['daylimsj'].$row['price'].$row['desreparation'].';
}
deja parcurge si afiseaza toate datele selectate din tabelul "orders" (reparatiile, daca asta selecteaza; tu stii).
Daca vrei sa fie afisate unele sub altele in pagina, trebuie doar sa adaugi un tag HTML <br /> de rasnd nou la "echo", asa:

Cod: Selectaţi tot

echo ' - '. $row['namerep']. $row['daylimsj']. $row['price']. $row['desreparation']. '<br/>';
 

tycyssg Mesaje:58
mersi , nu era atat de greu...eu ma gandeam ca e ceva mai complicat:D

Subiecte similare