Page 1 of 1

[php html mysql css] Any Help Sirs? tnx

Posted: Fri Jun 20, 2014 3:36 am
by Heartlock
I always get an error, though i tried ignoring it wih the use of "@"

Code: Select all


<?php
include 'connect.inc.php';

$query = "SELECT patno, compare, cubeno FROM tblcube WHERE cubeid = '1'";
	
							if($query_run = mysql_query($query)){	
								[b]while($row = @mysql_fetch_assoc($query_run)){[/b]
								$com = $row['compare'];
								$pat_no = $row['patno'];
								$cube_no = $row['cubeno'];
								
								if($com == $pat_no){
								echo "<th>".$pat_no."</th>";
								}
								else if ($com != $pat_no){

									echo"<th style = 'color:'DarkOrange'>".$pat_no."</th>";
									$query2 = "UPDATE tblcube set compare = '$pat_no'where cubeid = '1'";	
									if($query_run= mysql_query($query2)){
									}
								}
								
								}}

								/* error
								9
								Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in D:\xampp\htdocs\queue\c1v.php on line 6
								
								*/
								?>


								

what this page does is that it compares the new value of $pat_no and $com every certain period of time, then makes an output with different CSS(sadly the CSS doesnt take effect.)

here is the code where the output is being made

Code: Select all

<?php 
//connect to database
require 'connect.inc.php';

?>
<html>
	<head>
		<link rel="stylesheet" type="text/css" href="page1x.css" />
		
		<script src="ajax1.js"></script>
		<script type = "text/Javascript">
		refreshdiv_c1v();
		refreshdiv_c2v();
		refreshdiv_c3v();
		refreshdiv_c4v();
		refreshdiv_c5v();
		refreshdiv_c6v();
		refreshdiv_c7v();
		refreshdiv_c8v();
		</script>	
	</head>
	<body>
		<div>
		<table border = "8" class = "table1C-A">
		<tr id = "header">
			<th class = "heads">CONSULTATION DEPT.</th>
			<th class = "heads">NOW SERVING</th>
				<?php
							
							//cubicle1
							$query = "SELECT patno, cubeno FROM tblcube where cubeid = '1'";
							if($query_run = mysql_query($query)){	
								while($row = mysql_fetch_assoc($query_run)){
								$pat_no = $row['patno'];	
								$cube_no = $row['cubeno'];	
								
						 echo " <tr class = 'rows'>
								<th id = 'name'>".$cube_no."</th>
								<th id = 'num1'><div id = 'c1v'>".$pat_no."</div></th>	
								</tr>";
							}}
							
							//cubicle2
							$query = "SELECT patno, cubeno FROM tblcube where cubeid = '2'";
							if($query_run = mysql_query($query)){	
								while($row = mysql_fetch_assoc($query_run)){
								$pat_no = $row['patno'];	
								$cube_no = $row['cubeno'];	
						 echo " <tr class = 'rows'>
								<th id = 'name'>".$cube_no."</th>
								<th id = 'num'><div id = 'c2v'>".$pat_no."</div></th>	
								</tr>";
							}}
							
							//cubicle3
							$query = "SELECT patno, cubeno FROM tblcube where cubeid = '3'";
							if($query_run = mysql_query($query)){	
								while($row = mysql_fetch_assoc($query_run)){
								$pat_no = $row['patno'];	
								$cube_no = $row['cubeno'];	
						 echo " <tr class = 'rows'>
								<th id = 'name'>".$cube_no."</th>
								<th id = 'num'><div id = 'c3v'>".$pat_no."</div></th>	
								</tr>";
							}}
							
							//cubicle4
							$query = "SELECT patno, cubeno FROM tblcube where cubeid = '4'";
							if($query_run = mysql_query($query)){	
								while($row = mysql_fetch_assoc($query_run)){
								$pat_no = $row['patno'];	
								$cube_no = $row['cubeno'];	
						 echo " <tr class = 'rows'>
								<th id = 'name'>".$cube_no."</th>
								<th id = 'num'><div id = 'c4v'>".$pat_no."</div></th>	
								</tr>";
							}}
							
							//cubicle5
							$query = "SELECT patno, cubeno FROM tblcube where cubeid = '5'";
							if($query_run = mysql_query($query)){	
								while($row = mysql_fetch_assoc($query_run)){
								$pat_no = $row['patno'];	
								$cube_no = $row['cubeno'];	
						 echo " <tr class = 'rows'>
								<th id = 'name'>".$cube_no."</th>
								<th id = 'num'><div id = 'c5v'>".$pat_no."</div></th>	
								</tr>";
							}}
							//cubicle6
							$query = "SELECT patno, cubeno FROM tblcube where cubeid = '6'";
							if($query_run = mysql_query($query)){	
								while($row = mysql_fetch_assoc($query_run)){
								$pat_no = $row['patno'];	
								$cube_no = $row['cubeno'];	
						 echo " <tr class = 'rows'>
								<th id = 'name'>".$cube_no."</th>
								<th id = 'num'><div id = 'c6v'>".$pat_no."</div></th>	
								</tr>";
							}}
							
							//cubicle7
							$query = "SELECT patno, cubeno FROM tblcube where cubeid = '7'";
							if($query_run = mysql_query($query)){	
								while($row = mysql_fetch_assoc($query_run)){
								$pat_no = $row['patno'];	
								$cube_no = $row['cubeno'];	
						 echo " <tr class = 'rows'>
								<th id = 'name'>".$cube_no."</th>
								<th id = 'num'><div id = 'c7v'>".$pat_no."</div></th>	
								</tr>";
							}}
							
							
						//cubicle8
							$query = "SELECT patno, cubeno FROM tblcube where cubeid = '8'";
							if($query_run = mysql_query($query)){	
								while($row = mysql_fetch_assoc($query_run)){
								$pat_no = $row['patno'];	
								$cube_no = $row['cubeno'];	
						 echo " <tr class = 'rows'>
								<th id = 'name'>".$cube_no."</th>
								<th id = 'num'><div id = 'c8v'>".$pat_no."</div></th>	
								</tr>";
							}}							
							?>
		</table>
		</div>
	</body>
</html>


Why do I get such an error even if I still get the output and also, how do I make it so that the CSS also changes
any help is greatly appreciated! Thanks!

Re: [php html mysql css] Any Help Sirs? tnx

Posted: Fri Jun 20, 2014 6:38 am
by Celauran
What error(s) are you encountering?

Re: [php html mysql css] Any Help Sirs? tnx

Posted: Fri Jun 20, 2014 6:43 am
by Celauran

Code: Select all

//cubicle1
$query = "SELECT patno, cubeno FROM tblcube where cubeid = '1'";
if ($query_run = mysql_query($query)) {
	while ($row = mysql_fetch_assoc($query_run)) {
		$pat_no = $row['patno'];
		$cube_no = $row['cubeno'];
		echo " <tr class = 'rows'>
		<th id = 'name'>".$cube_no."</th>
		<th id = 'num1'><div id = 'c1v'>".$pat_no."</div></th>
		</tr>";
	}
}

//cubicle2
$query = "SELECT patno, cubeno FROM tblcube where cubeid = '2'";
if ($query_run = mysql_query($query)) {
	while ($row = mysql_fetch_assoc($query_run)) {
		$pat_no = $row['patno'];
		$cube_no = $row['cubeno'];
			echo " <tr class = 'rows'>
			<th id = 'name'>".$cube_no."</th>
			<th id = 'num'><div id = 'c2v'>".$pat_no."</div></th>
			</tr>";
	}
}
Use of mysql_query etc notwithstanding, you're repeating yourself over and over. Just use a loop. Also, you've got repeated IDs all over the place. IDs cannot be repeated. Use classes here.