Jump to content

displaying results using splits


dannyone

Recommended Posts

i have this code i have been working on, and its works quite neatly at storing the values in the DB. however i now need to query the results stored, but i can only query the first value in the field because of the split. can some1 advise me on the best way to work around this?

 

<?

// All database details will be included here 

// updating the record if form is submitted ////////
// This section will come into picture if the form is submitted // 
@$todo=$_POST['todo']; // take care of register global if off
if(isset($todo) and $todo=="submit_form"){
$days_array=$_POST['days_array'];
$tag_string="";
while (list ($key,$val) = @each ($days_array)) {
//echo "$val,";
$tag_string.=$val.",";
}
$tag_string=substr($tag_string,0,(strLen($tag_string)-1));
$result=(mysql_query("update Marker_Free set timeslot='$tag_string' where Marker_ID= '" .$_SESSION['login'] . "'"));
if(mysql_affected_rows()==0) {
$result=mysql_query("INSERT INTO Marker_Free (Marker_ID, timeslot) VALUES('" .$_SESSION['login'] . "', '$tag_string')");
echo "Your Availability has been updated<br><br />"; 
}else{echo mysql_error();}

}
// End of updating the record ////

//////// Displaying the days ///////////
$query="select timeslot from Marker_Free where Marker_ID= '" .$_SESSION['login'] . "'";
$row=mysql_fetch_object(mysql_query($query));



$days_array=split(",",$row->timeslot);       <-- here im splitting the values and need help retrning them



$qt=mysql_query("select * from DaysTimes");

echo "<form method=post action=''><input type=hidden name=todo value=submit_form>";
echo "<table border='0' width='50%' cellspacing='0' cellpadding='0' align=center>";
$st="";
while($noticia=mysql_fetch_array($qt)){

if(@$bgcolor=='#f1f1f1'){$bgcolor='#ffffff';}
else{$bgcolor='#f1f1f1';}
if(in_array($noticia['id'],$days_array)){$st="checked";}
else{$st="";}
echo "<tr bgcolor='$bgcolor'>
<td class='data'><input type=checkbox name=days_array[] value='$noticia[id]' $st> $noticia[days], $noticia[timeslot] </td></tr>";

}



echo  "</table>
<input type=submit value='Update Availability'>
</form>

</center>";

?>

 

 

i just need to know how i can view all results in the query

 

thanks

Link to comment
Share on other sites

sorry i forgot to say this is the current query im using on another page, and its only returning the 1st value

$query =("SELECT Marker_Free.Marker_ID,Marker_Free.timeslot,DaysTimes.id,DaysTimes.timeslot,DaysTimes.days,DaysTimes.timeslots FROM Marker_Free,DaysTimes where Marker_ID = '" .$_SESSION['login'] . "' AND Marker_Free.timeslot = DaysTimes.id");

$result = mysql_query ($query);

while($row = mysql_fetch_array($result)){

echo "marker name: ".$row['Marker_ID'] ."<br /><br />";
echo " times available: ".$row['timeslots'] . " On ".$row['days'];
}

Link to comment
Share on other sites

sorry, when a user checks a box from DaysTimes, it is then stored with the marker-id in the Marker_Free table,

 

for example if the user selects checkbox 2 and 8 its shows like this in my table

 

Marker_ID    timeslot

100              2,8

 

because im using the id from DaysTimes to = timeslot

 

im a little worried about my database design because i want to create a list of 10 checkboxs, like this;

 

checkbox    monday  9-12

checkbox    monday  12-4

checkbox    tuesday  9-12

etc.... to friday 12-4

 

so when the user selects the 1st box i want it to store the values 9-10,10-11,11-12 Monday. so that i can compare it at another time.

 

so at the moment i have added timeslots to the DaysTimes table;

 

id    timeslot    day        timeslots

2      12-4        mon      12-1,1-2,2-3,3-4

8      12-4        thurs      12-1,1-2,2-3,3-4

 

i hope this makes sence haha

 

can any of this work? im not very good at php

 

thanks

 

Link to comment
Share on other sites

yeah im trying to make 1 were it compares 3 users timetables. 1 user has a set timetable, and the other 2 can specify their availability. the first users timetable is split up into 1 hours times like 9-10. so i need the other 2 users to select times they are available from a like of grouped hours and then split them up into  1 hours sessions again.

 

can you help?

 

thanks

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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