Jump to content


Photo

Not working, but not getting an error


  • Please log in to reply
24 replies to this topic

#21 alexruimy

alexruimy
  • Members
  • PipPip
  • Member
  • 20 posts

Posted 14 June 2006 - 02:55 PM

Right, I am echoing the query on the page. [a href=\"http://artelcommunications.net/test/view.php\" target=\"_blank\"]http://artelcommunications.net/test/view.php[/a]

What's SQL Error Trapping?

Thanks again.

#22 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 14 June 2006 - 03:05 PM

error trapping example...

$result = mysql_query($query) or die("error: ". mysql_error(). " with query ". $query); // that helps

OK, I see that the echo'd query changes properly and that the displayed data never changes regardless of what 'order' I wanted. That looks as though the data are being displayed without regard to the echo'd query - which makes me wonder if there's another query (without any sort instruction) being used to actually retrieve the data for display.

I'm not sure you've posted the relevant part of your code - all the way from the query to actually displaying the tabular data. If you have, aplogies; if you haven't can we see?
Legend has it that reading the manual never killed anyone.
My site

#23 alexruimy

alexruimy
  • Members
  • PipPip
  • Member
  • 20 posts

Posted 14 June 2006 - 03:07 PM

[!--quoteo(post=383845:date=Jun 14 2006, 11:05 AM:name=AndyB)--][div class=\'quotetop\']QUOTE(AndyB @ Jun 14 2006, 11:05 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
error trapping example...

$result = mysql_query($query) or die("error: ". mysql_error(). " with query ". $query); // that helps

OK, I see that the echo'd query changes properly and that the displayed data never changes regardless of what 'order' I wanted. That looks as though the data are being displayed without regard to the echo'd query - which makes me wonder if there's another query (without any sort instruction) being used to actually retrieve the data for display.

I'm not sure you've posted the relevant part of your code - all the way from the query to actually displaying the tabular data. If you have, aplogies; if you haven't can we see?
[/quote]
If I didn't post the relevant part, I'm gonna feel like an idiot :-P.

Anyway, here's the entire page:

<?
if (!$sort){
$sort = "ASC";
}

if ($sort == "ASC"){
$sort2 = "DESC";
}

if ($sort == "DESC"){
$sort2 = "ASC";
}

$username="sdf";
$password="sdfdfsd";
$database="sdfsdf";
$heh="sdfsdf";

mysql_connect($heh,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");


if (!$orderby){
$query = "SELECT * FROM extensions ORDER BY `ext` $sort";
$result = mysql_query($query);
}

if ($orderby){
$orderby= "ext";
$query = "SELECT * FROM extensions ORDER BY `" . $_GET['orderby']. "` $sort";
$result = mysql_query($query);

}

$num=mysql_num_rows($result);
echo "$query";

?>
<html>
<head>
<title>NYC DEP Extensions Chart</title>
<style>
body {background-color:black;}
* {font-family: verdana, arial, sans-serif; font-size:12px; color:white;}
.hover {font-weight:bold; font-size:14px;}
a:hover {background-color:9999ff; color:black;}
.heading {font-size:16px; font-weight:bold; text-align:center;}
.td1 {background-color:#808080;}
.td2 {background-color:#636363;}
.hidden {display:none;}
</style>
<script type="text/javascript">
<!--
function hide( id, id2 )
{
document.getElementById(id).style.display = 'block';
document.getElementById(id2).style.display = 'none';
}
//-->
</script> 
</head>
<body>

<table width="80%" align="center" cellspacing="0">
<tr>
<td class="heading" colspan="6">NYC DEP Phone Extensions</td>
</tr>
<tr>
<td colspan="6">
<div class="hidden" id="stats"><? include("stats.php"); ?>
<div onclick="hide('show','stats');"><a>(Hide Stats)</div></a></div>
<div onclick="hide('stats','show');" id="show"><a>(Show Stats)</a></div></td>
</tr>
<tr>
<td colspan="6" align="center"><br>
<a href="export.php?orderby=<? echo $orderby; ?>">Export to Excel</a></td>
</tr>
<tr>
<td class="1"><b><a href="view.php?orderby=ext">Ext</a></b></td>
<td class="1"><b><a href="view.php?orderby=building">Building</a></b></td>
<td class="1"><b><a href="view.php?orderby=type">Phone</a></a></b></td>
<td class="1"><b><a href="view.php?orderby=room">Room</b></td>
<td class="1"><b><a href="view.php?orderby=floor">Floor</a></b></td>
<td class="1"><b><a href="view.php?orderby=elevation">Elevation</a></b></td>
</tr>

<?
$i=0;
$i2 = 1;
while ($i < $num) {

if ($i2 % 2 == 0 ) {
$incl = "class=\"td1\"";
}
else {
$incl = "class=\"td2\"";
}

$ext=mysql_result($result,$i,"ext");
$building=mysql_result($result,$i,"building");
$type=mysql_result($result,$i,"type");
$room=mysql_result($result,$i,"room");
$floor=mysql_result($result,$i,"floor");
$el=mysql_result($result,$i,"elevation");

echo "<tr>
<td $incl>$ext</td>
<td $incl>$building</td>
<td $incl>$type</td>
<td $incl>$room</td>
<td $incl>$floor</td>
<td $incl>$el</td>
</tr>
";

$i++;
$i2++;
}

mysql_close();

?>
</table>
</body>
</html>


#24 joquius

joquius
  • Members
  • PipPipPip
  • Advanced Member
  • 319 posts

Posted 14 June 2006 - 03:09 PM

if (!$orderby){
$query = "SELECT * FROM extensions ORDER BY `ext` $sort";
$result = mysql_query($query);
}

if ($orderby){
$orderby= "ext";
$query = "SELECT * FROM extensions ORDER BY `" . $_GET['orderby']. "` $sort";
$result = mysql_query($query);

}

change this to

if (!isset ($_GET['orderby'])){
$query = "SELECT * FROM extensions ORDER BY `ext` $sort";
$result = mysql_query($query);
}

if (isset ($_GET['orderby'])){
$query = "SELECT * FROM extensions ORDER BY `" . $_GET['orderby']. "` $sort";
$result = mysql_query($query);

}

what am I saying

$orderby = (isset ($_GET['orderby'])) ? $_GET['orderby'] : "ext";
$query = "SELECT * FROM extensions ORDER BY `$orderby` $sort";
$result = mysql_query($query);
z..z..z..z..z..z..z..z..

#25 alexruimy

alexruimy
  • Members
  • PipPip
  • Member
  • 20 posts

Posted 14 June 2006 - 03:22 PM

Okay, I was playing around with it and I got it. It had to do, I believe, with my including the "stats.php" file. Here's the corrected code, also available at [a href=\"http://artelcommunications.net/test/view2.php\" target=\"_blank\"]http://artelcommunications.net/test/view2.php[/a]


<html>
<head>
<title>NYC DEP Extensions Chart</title>
<style>
body {background-color:black;}
* {font-family: verdana, arial, sans-serif; font-size:12px; color:white;}
.hover {font-weight:bold; font-size:14px;}
a:hover {background-color:9999ff; color:black;}
.heading {font-size:16px; font-weight:bold; text-align:center;}
.td1 {background-color:#808080;}
.td2 {background-color:#636363;}
.hidden {display:none;}
</style>
<script type="text/javascript">
<!--
function hide( id, id2 )
{
document.getElementById(id).style.display = 'block';
document.getElementById(id2).style.display = 'none';
}
//-->
</script> 
</head>
<body>

<table width="80%" align="center" cellspacing="0">
<tr>
<td class="heading" colspan="6">NYC DEP Phone Extensions</td>
</tr>
<tr>
<td colspan="6">
<div class="hidden" id="stats"><? include("stats2.php"); ?>
<div onclick="hide('show','stats');"><a>(Hide Stats)</div></a></div>
<div onclick="hide('stats','show');" id="show"><a>(Show Stats)</a></div></td>
</tr>
<tr>
<td colspan="6" align="center"><br>
<a href="export.php?orderby=<? echo $orderby; ?>">Export to Excel</a></td>
</tr>
<tr>
<td class="1"><b><a href="view2.php?orderby=ext">Ext</a></b></td>
<td class="1"><b><a href="view2.php?orderby=building">Building</a></b></td>
<td class="1"><b><a href="view2.php?orderby=type">Phone</a></a></b></td>
<td class="1"><b><a href="view2.php?orderby=room">Room</b></td>
<td class="1"><b><a href="view2.php?orderby=floor">Floor</a></b></td>
<td class="1"><b><a href="view2.php?orderby=elevation">Elevation</a></b></td>
</tr>
<?
if (!$sort){
$sort = "ASC";
}

if ($sort == "ASC"){
$sort2 = "DESC";
}

if ($sort == "DESC"){
$sort2 = "ASC";
}

$username="52542m";
$password="atsfsdfm";
$database="sdfsdfdf";
$heh="asdfsdfict";

mysql_connect($heh,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");


if (!$orderby){
$query = "SELECT * FROM extensions ORDER BY `ext` $sort";
$result = mysql_query($query);
}

if ($orderby){
$orderby= "ext";
$query = "SELECT * FROM extensions ORDER BY `" . $_GET['orderby']. "` $sort";
$result = mysql_query($query);

}

$num=mysql_num_rows($result);
echo "$query";

?>
<?
$i=0;
$i2 = 1;
while ($i < $num) {

if ($i2 % 2 == 0 ) {
$incl = "class=\"td1\"";
}
else {
$incl = "class=\"td2\"";
}

$ext=mysql_result($result,$i,"ext");
$building=mysql_result($result,$i,"building");
$type=mysql_result($result,$i,"type");
$room=mysql_result($result,$i,"room");
$floor=mysql_result($result,$i,"floor");
$el=mysql_result($result,$i,"elevation");

echo "<tr>
<td $incl>$ext</td>
<td $incl>$building</td>
<td $incl>$type</td>
<td $incl>$room</td>
<td $incl>$floor</td>
<td $incl>$el</td>
</tr>
";

$i++;
$i2++;
}

mysql_close();

?>
</table>
</body>
</html>

Thanks all for your help.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users