Jump to content

query -> result -> foreach -> numrows result2


NoDoze

Recommended Posts

I'm not sure how to go about this, so I'm just going to put it out there for some ideas...

 

This is for web based scheduling team practices...

 

table

id

id2

date

time

avail

 

- I have the admin entering the practice schedule. Including an id2 value '1'

- A player pulls up the schedule...the pull down menu submits the avail... I already have it set so that if the schedule has an id2 value it makes an insert, if the id2 has no value it does an update. That way the admin entries are retained, and the players avail is retained.

- now when a player pulls up their schedule, as you can see now I run into the schedule having multiple entries for each player depending on the avail for each date/practice. Because the select statement is for all practices both the admin entered and the player avail entries.

- I want the admin entries to ALWAYS stay there.

- But I need a query select all entires for a player, but if a particular date/time is identical to only show the one with no id2 value (aka the one with the players avail).

 

Basically, if the player hasn't entered their avil, I want it to show the admin entry. And vise vera, if the player has enter their avil, the admin entry doesn't show.

 

What kind of query would that be!?!

 

I suspect I query all entires = result

take that result, and foreach entry that is identical (==), it picks the entry with id2=''

then shows that new result.

 

Is my thinking correct?

How would I go about doing this?

 

...Or is there a better way of doing it? ...any ideas?

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/207051-query-result-foreach-numrows-result2/
Share on other sites

ok....so no responses yet!?! LOL Guess no one is up for my challenge! ;)

 

Well, this is what I have so far...

 

<?php

include 'config.php';
include 'opendb.php';


$query="SELECT * FROM dates WHERE username='$username' AND team='$team' ORDER BY date";

$result=mysql_query($query) or die("SELECT Error: ".mysql_error());;


mysql_close();

$num=mysql_numrows($result);
$i=0;
while ($i < $num) {

if ($type == $date && $time ==$location)
{
unset ($num);
}

$id=mysql_result($result,$i,"id");
$id2=mysql_result($result,$i,"id2");
$type=mysql_result($result,$i,"type");
$date=mysql_result($result,$i,"date");
$time=mysql_result($result,$i,"time");
$location=mysql_result($result,$i,"location");
$avail=mysql_result($result,$i,"avail");



include 'schedoption1.php';

++$i;
}
?>

 

...but this only shows one result....

 

...any help is appreciated...

 

Thanks!

ok, since I'm getting no responses, maybe I'm making it a bit too confusing....so let me try to explain what I'm trying to do better....

 

ok...I have a table with these entries....

 

0-5-8-3

0-4-6-7

1-4-6-7

1-5-8-3

1-7-2-3

 

I need to display all the rows with 0's...but if there isn't a '0' row for 1-7-2-3, I need it to display 1-7-2-3.

That's it in a nut shell...

 

Any ideas?

 

Can I do this with a mysql query?

Or can I do this with an if statement?

 

My guess is a select * mysql query, but then need an if statement to determine if the row has a 0 or 1...?

 

I'm stumped!

 

ANY direction, examples, ideas = HELP :)

 

Thanks!

 

Archived

This topic is now archived and is closed to further replies.

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