Jump to content

dannyone

Members
  • Posts

    57
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

dannyone's Achievements

Member

Member (2/5)

0

Reputation

  1. Hey, i have used phpmyadmin and my query works fine and displays all the correct records. however now i am trying to show them in html and its seems that it isn't storing some of the values i am selecting. il show you my code so i can explain better $days = array('mon' => '', 'tue' => '', 'wed' => '', 'thu' => '', 'fri' => ''); // Add our list of days to our time slots $times = array( '9-10' => $days, '10-11' => $days, '11-12' => $days, '12-1' => $days, '1-2' => $days, '2-3' => $days, '3-4' => $days); // Connect to DB and run our query $sql = new mysqli('localhost', 'danny', 'danny', 'tutorial'); $run = $sql->query("SELECT Marker_Rooms.Room_ID2, Rooms_Free.Room_ID, Rooms_Free.timeslot, Rooms_Free.day, Rooms_Free.status FROM Marker_Rooms, Rooms_Free WHERE Marker_ID = '101' AND Marker_Rooms.Room_ID = Rooms_Free.Room_ID AND Rooms_Free.status = '0' UNION SELECT Marker_Rooms.Room_ID1, Rooms_Free.Room_ID, Rooms_Free.timeslot, Rooms_Free.day, Rooms_Free.status FROM Marker_Rooms, Rooms_Free WHERE Marker_ID = '101' AND Marker_Rooms.Room_ID1 = Rooms_Free.Room_ID AND Rooms_Free.status = '0' UNION SELECT Marker_Rooms.Room_ID2, Rooms_Free.Room_ID, Rooms_Free.timeslot, Rooms_Free.day, Rooms_Free.status FROM Marker_Rooms, Rooms_Free WHERE Marker_ID = '101' AND Marker_Rooms.Room_ID2 = Rooms_Free.Room_ID AND Rooms_Free.status = '0'"); while($row = $run->fetch_object()) { $times[$row->timeslot][$row->day] = "<input type=radio name=radio[] id=radio[] value= $row->id/> $row->Room_ID <br> <input type=radio name=radio[] id=radio[] value= $row->id/> $row->Room_ID1 <br> <input type=radio name=radio[] id=radio[] value= $row->id/> $row->Room_ID2"; //////////////////////////////////////////////////////////////// above is my problem! } $body = <<< endBody <center> <table align="center" border="1" cellspacing="0" cellpadding="1"> <tr> <th align="center">Time</th> <th align="center">Monday</th> <th align="center">Tuesday</th> <th align="center">Wednesday</th> <th align="center">Thursday</th> <th align="center">Friday</th> </tr> endBody; // For each time slot, check each day for a value // If one exists, display it, if not, display an empty table data (<td>) foreach($times as $timeslot => $day) { $body .= "\n\t\t<tr>\n\t\t\t<td>$timeslot</td>"; foreach($day as $course) { $td = (strlen($course) > 0) ? $course : ' '; $body .= "\n\t\t\t<td>$td</td>"; } $body .= "\n\t\t</tr>"; } $body .= "\n\t</table>\n</center"; ?> <?=$body?> i am trying to show all the Room_ID's with a radio button that have status 0. however it doesn't work, it just show Room_ID, not Room_ID1 or Room_ID2. i have tried just using Room_ID1 and nothing appears so i guess im not selecting it properly. does any1 have any ideas? Thanks
  2. ok i have sorted it now thanks anyways
  3. hello everyone i have a problem, i have got 3 working querys, to show on seperate tables, however i need to either combine these 3 querys to show all the information in one table, or i need to run the querys straight after each other so i can do it. my aim is to show a table of all the times that are available for 3 selected rooms. the 3 querys i have work , seperatly, but i dont know how to join them. can any one help here are my 3 working querys "SELECT Marker_Rooms.Room_ID, Rooms_Free.Room_ID, Rooms_Free.timeslot, Rooms_Free.day, Rooms_Free.status FROM Marker_Rooms, Rooms_Free WHERE Marker_ID = '" .$_SESSION['login'] . "' AND Marker_Rooms.Room_ID = Rooms_Free.Room_ID AND Rooms_Free.status = '0'" SELECT Marker_Rooms.Room_ID1, Rooms_Free.Room_ID, Rooms_Free.timeslot, Rooms_Free.day, Rooms_Free.status FROM Marker_Rooms, Rooms_Free WHERE Marker_ID = '" .$_SESSION['login'] . "' AND Marker_Rooms.Room_ID1 = Rooms_Free.Room_ID AND Rooms_Free.status = '0'" "SELECT Marker_Rooms.Room_ID2, Rooms_Free.Room_ID, Rooms_Free.timeslot, Rooms_Free.day, Rooms_Free.status FROM Marker_Rooms, Rooms_Free WHERE Marker_ID = '" .$_SESSION['login'] . "' AND Marker_Rooms.Room_ID2 = Rooms_Free.Room_ID AND Rooms_Free.status = '0'" Here is a query i tried but it just displays all records in the table regardless is they have status 0 or not. "SELECT Marker_Rooms.Room_ID, Marker_Rooms.Room_ID1, Marker_Rooms.Room_ID2, Rooms_Free.Room_ID, Rooms_Free.timeslot, Rooms_Free.day, Rooms_Free.status FROM Marker_Rooms, Rooms_Free WHERE (Marker_Rooms.Room_ID = Rooms_Free.Room_ID AND Marker_Rooms.Marker_ID = '" .$_SESSION['login'] . "' AND Rooms_Free.status = '0') OR (Marker_Rooms.Room_ID1 = Rooms_Free.Room_ID AND Marker_Rooms.Marker_ID = '" .$_SESSION['login'] . "' AND Rooms_Free.status = '0') OR (Marker_Rooms.Room_ID2 = Rooms_Free.Room_ID AND Marker_Rooms.Marker_ID = '" .$_SESSION['login'] . "' AND Rooms_Free.status = '0')" any help would be fantastic Thanks
  4. thanks maq, i saved it in a session and it worked an absolute treat!!
  5. i have created a dynamic dropdown from my mysql database, and the value selected is posted to a new page, as follows $room = $_POST['room']; now i can use that value on the other page to collect more information from my database. however i now need to post that value again, this time into my database using an update query, but when i press submit it looses the value and looses all the information linked to it on the page. is there a way of reposting the value? or another way round this? im seriously confused can any1 help? Thanks
  6. ok iv managed to do it now.. thanks every1 for their help. i just couldn't get my head around it at first! i have another question tho, once i have updated the database, i want to query the database again and disable tick the rows were status = 1, so that users can view them but not edit them. is there a simple solution? thanks
  7. i have been trying to use the tutorial from the php freaks tutorial for checkboxes and for some reason it wont work. i have created the tables properly and it connects to my database, however it wont select any of my data from the database does anyone know why? thanks
  8. i havn't redarrow, hope you don't mind but how do i use that? thanks
  9. Thanks again Brian. i have tried using your code but i just couldn't get my head around it, im not that good with php/mysql. i have been reading up and i have this now, but the problem is it updates all the records to which room is selected. i just want it to update the checkbox selected, can any1 advise me how i would this? <html> <body> <form method="post" action="<?php echo $PHP_SELF;?>"> <?php mysql_connect("localhost", "danny", "danny") or die("Connection Failed"); mysql_select_db("tutorial")or die("Connection Failed"); ?> <br> <?php $car = $_POST['car']; mysql_connect("localhost", "danny", "danny") or die(mysql_error()); echo "Connected to MySQL<br />"; mysql_select_db("tutorial") or die(mysql_error()); echo "Connected to Database<br /><br />"; $result1 = mysql_query("UPDATE test SET status='$car' WHERE status='0' AND Room_ID='101'") or die(mysql_error()); $query = "SELECT * FROM test WHERE Room_ID = '101'"; $result = mysql_query($query); while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { ?> <input type="checkbox" name="car" value="1"><?php echo $line[day], $line[timeslot], $line[Room_ID]?> <br> <?php if ($_POST['car']=="1") { echo "YES<br>"; } else { echo "NO<br>"; } } ?> </body> </html> <input type="submit" value="submit" name="submit"> <br /> <br /> </form> </html> </form> </table> </form> </html> my db is room_id, timeslot, day, status 1 9-10 Monday 0 the select statement works and shows all the correct room details and checkboxes, but when i click on 1 checkbox it updates the status of all of them. do i need a foreach loop or something? thanks
  10. yeah sorry these are the checkboxes i was using <body> <table width="200" border="1"> <tr> <td> </td> <td>09:00</td> <td>10:00</td> <td>11:00</td> <td>12:00</td> <td>13:00</td> <td>14:00</td> <td>15:00</td> </tr> <tr> <td><div align="center">Monday</div></td> <td> <div align="center"> <input type="checkbox" name="Monday910[][]" value="whatever" /> </div> </form> </td> <td><div align="center"> <input type="checkbox" name="Monday1011[][]" value="whatever" /> </div></td> <td><div align="center"> <input type="checkbox" name="Monday1112[][]" value="whatever" /> </div></td> <td><div align="center"> <input type="checkbox" name="Monday121[][]" value="whatever" /> </div></td> <td><div align="center"> <input type="checkbox" name="Monday12[][]" value="whatever" /> </div></td> <td><div align="center"> <input type="checkbox" name="Monday23[][]" value="whatever" /> </div></td> <td><div align="center"> <input type="checkbox" name="Monday34[][]" value="whatever" /> </div></td> </tr> <tr> <td><div align="center">Tuesday</div></td> <td><div align="center"> <input type="checkbox" name="Tuesday910[][]" value="whatever" /> </div></td> <td><div align="center"> <input type="checkbox" name="Tuesday1011[][]" value="whatever" /> </div></td> <td><div align="center"> <input type="checkbox" name="Tuesday1112[][]" value="whatever" /> </div></td> <td><div align="center"> <input type="checkbox" name="Tuesday121[][]" value="whatever" /> </div></td> <td><div align="center"> <input type="checkbox" name="Tuesday12[][]" value="whatever" /> </div></td> <td><div align="center"> <input type="checkbox" name="Tuesday23[][]" value="whatever" /> </div></td> <td><div align="center"> <input type="checkbox" name="Tuesday34[][]" value="whatever" /> </div></td> </tr> <tr> <td><div align="center">Wednesday</div></td> <td><div align="center"> <input type="checkbox" name="Wednesday910[][]" value="whatever" /> </div></td> <td><div align="center"> <input type="checkbox" name="Wednesday1011[][]" value="whatever" /> </div></td> <td><div align="center"> <input type="checkbox" name="Wednesday1112[][]" value="whatever" /> </div></td> <td><div align="center"> <input type="checkbox" name="Wednesday121[][]" value="whatever" /> </div></td> <td><div align="center"> <input type="checkbox" name="Wednesday12[][]" value="whatever" /> </div></td> <td><div align="center"> <input type="checkbox" name="Wednesday23[][]" value="whatever" /> </div></td> <td><div align="center"> <input type="checkbox" name="Wednesday34[][]" value="whatever" /> </div></td> </tr> <tr> <td><div align="center">Thursday</div></td> <td><div align="center"> <input type="checkbox" name="Thursday910[][]" value="whatever" /> </div></td> <td><div align="center"> <input type="checkbox" name="Thursday1011[][]" value="whatever" /> </div></td> <td><div align="center"> <input type="checkbox" name="Thursday1112[][]" value="whatever" /> </div></td> <td><div align="center"> <input type="checkbox" name="Thursday121[][]" value="whatever" /> </div></td> <td><div align="center"> <input type="checkbox" name="Thursday12[][]" value="whatever" /> </div></td> <td><div align="center"> <input type="checkbox" name="Thursday23[][]" value="whatever" /> </div></td> <td><div align="center"> <input type="checkbox" name="Thursday34[][]" value="whatever" /> </div></td> </tr> <tr> <td><div align="center">Friday</div></td> <td><div align="center"> <input type="checkbox" name="Friday910[][]" value="whatever" /> </div></td> <td><div align="center"> <input type="checkbox" name="Friday1011[][]" value="whatever" /> </div></td> <td><div align="center"> <input type="checkbox" name="Friday1112[][]" value="whatever" /> </div></td> <td><div align="center"> <input type="checkbox" name="Friday121[][]" value="whatever" /> </div></td> <td><div align="center"> <input type="checkbox" name="Friday12[][]" value="whatever" /> </div></td> <td><div align="center"> <input type="checkbox" name="Friday23[][]" value="whatever" /> </div></td> <td><div align="center"> <input type="checkbox" name="Friday34[][]" value="whatever" /> </div></td> </tr> </body> im not sure how im going to work them though thanks
  11. ok il try to explain the best i can. i have a drop down list which i can choose a room from. once i have chosen the room i then want to be able to choose times from a list of checkboxes and update the records in my database. The checkboxes will be in a table like mon tue wed 9 checkbox checkbox 10 checkbox 11 etc... i simply want to update 1 field in my db from 0 to 1, when that checkbox is ticked. my db looks like room, time, day, int 1 9 M 0 i want the rooms details selected in the dropdown to be updated so that int would change to 1. so room, time, day, int 1 9 M 1 i have all the fields in the database and i can do the dropdown, but i havent got a clue with the checkboxs and updating the db. i had help previously to insert the data into a db using mulit dimensional arrays, but its not the right design for this page i have, i just need to update a field. any help would be great Thanks
  12. hello everyone i have a rather complex query that i am trying to make but i just can't figure out how im going to do it, here is my table structure Marker_Free table Marker_ID, timeslot, day, status Marker_Rooms table Marker_ID, Room_ID Rooms_Free table Room_ID, timeslot, day, status now what i need to do is compare all the data in these tables and show them in a html table. i have attempted to do the query and i can get it to display the room availability for tht user, but i also want it to show that markers availability on the same table. i have two seperate querys that do these, but i need to make them into 1 so i can show all the results. can some1 have a look and try and help me combine the queries so that it works. any help would be greatly appreciated! this code displays Room availability for the user "SELECT Mf.Marker_ID, Mf.timeslot, Mf.day, Mf.Status, Rf.Room_ID, Rf.timeslot, Rf.day, Rf.status, Mr.Marker_ID, Mr.Room_ID FROM Marker_Free AS Mf INNER JOIN Marker_Rooms AS Mr ON (Mf.Marker_ID = Mr.Marker_ID) INNER JOIN Rooms_Free AS Rf ON (Mr.Room_ID = Rf.Room_ID) WHERE Mf.Marker_ID = '" .$_SESSION['login'] . "'"); this code displays that Markers availability "SELECT Marker_ID, timeslot, day, Status FROM Marker_Free WHERE Marker_ID = '" .$_SESSION['login'] . "'"); Thanks in advance!
  13. thanks for the reply Maq, i have tried using your code and modifying to match my data but it doesn't seem to work it just gives me a blank page. do i need to add more detail into it to get it to work? <?php $user = $_SESSION['login']; mysql_connect("localhost", "xx", "xx") or die(mysql_error()); mysql_select_db("xx") or die(mysql_error()); $result = myql_query("SELECT * FROM Marker_Rooms WHERE Marker_ID = '$user'") or die(mysql_error()); if(mysql_num_rows($result) > 0) { echo "sorry, you're already in the DB"; } else { echo "not in the DB, do whatever you want in this block"; } ?> im already calling session further up so not included it here thanks
  14. hello, im wondering if there is a way to do this. i have a page where users can select from a few drop downs some values and save them into a db. is there a way to create a query were if the user exists in the db then they can not use that page? im storing the user_id in a session. any help would be greatly appreciated. thanks
  15. iv been working on this for a bit now since the last comment and iv got a little further. when i echo the value now it always shows the last value that is been called from the mysql table. can some1 help and just see were im going wrong please, im really stuck <form method="post" action="<?php echo $PHP_SELF;?>"> <body> <?php mysql_connect("localhost", "xx", "xx") or die(mysql_error()); echo "Connected to MySQL<br />"; mysql_select_db("xx") or die(mysql_error()); "<br/>"; echo "Connected to Database"; "<br>"; "<br>"; $query=("select Room_ID, RoomName from Rooms ORDER BY Room_ID"); $result=mysql_query($query) or die ("Unable to Make the Query:" . mysql_error() ); while($row=mysql_fetch_array($result)){ $category = $row["Room_ID"]; "<br/>"; "<br/>"; echo "<input type=\"checkbox\" name=\"category[]\" value=\"\"> $category:"; echo "<br>"; } echo "".$category.""; ?> <input type="submit" value="submit" name="submit"> <br /> <br /> </form> </html> thanks
×
×
  • 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.