Closed Thread Icon

Topic awaiting preservation: php/mysql within a table (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=21620" title="Pages that link to Topic awaiting preservation: php/mysql within a table (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: php/mysql within a table <span class="small">(Page 1 of 1)</span>\

 
CRO8
Bipolar (III) Inmate

From: New York City
Insane since: Jul 2000

posted posted 05-01-2004 16:18

for some reason my code is not processing and all I get is a blank page . . . can php/mysql be within a table? silly question but I have to start somewhere.

Thanks.

WarMage
Maniac (V) Mad Scientist

From: Rochester, New York, USA
Insane since: May 2000

posted posted 05-01-2004 17:09

Yes. And if you post your code snippet we might be able to actually help...

norm
Paranoid (IV) Inmate

From: [s]underwater[/s] under-snow in Juneau
Insane since: Sep 2002

posted posted 05-02-2004 03:11

Nine times out of Ten....a blank page is caused by a missing semicolon at the end of a statement. Of course this is just a guess since you didn't post your code.

/* Sure, go ahead and code in your fancy IDE. Just remember: it's all fun and games until someone puts an $i out */

CRO8
Bipolar (III) Inmate

From: New York City
Insane since: Jul 2000

posted posted 05-02-2004 03:31

sorry guys.

code:
<table width="750" border="0" cellspacing="0" cellpadding="0" vspace="0" hspace="0" height="0" align="center">
<tr align="left" valign="top">
<td height="125" colspan="3">
<table width="750" border="1" cellspacing="0" cellpadding="0" height="125" bordercolor="#000000">
<tr align="left" valign="top">
<td valign="middle" align="center" width="186"><font size="6">Logo</font></td>
<td width="339" align="center" valign="middle"><font size="4">Welcome
&amp; alt. banners for other pages</font></td>
<td width="225" align="center" valign="middle">
<p><a href="#">Bookmark Coupon Pile</a></p>
<p><a href="#">Subscribe to our Coupon Circular</a></p>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td height="5" valign="bottom" colspan="3"><img src="/images/black_line.gif" width="100%" height="1"></td>
</tr>
<tr>
<td colspan="3" height="20">
<div align="center"><font face="Arial, Helvetica, sans-serif" size="2"><a href="#">See
All Our Merchants</a> &nbsp;&nbsp;<a href="#">New Coupons</a> &nbsp;&nbsp;<a href="#">Expiring Coupons</a> &nbsp;&nbsp;<a href="#">Free Stuff</a>
&nbsp;&nbsp;<a href="#">Testimonials</a> &nbsp;&nbsp;<a href="#">About
Us</a>&nbsp;&nbsp;<a href="#">Terms of Use</a></font></div>
</td>
</tr>
<tr>
<td height="1" colspan="3"><img src="/images/black_line.gif" width="100%" height="1"></td>
</tr>
<tr align="left" valign="top">
<td colspan="3" height="400">
<table width="100%" border="0" cellspacing="0" cellpadding="0" height="100%">
<tr align="left" valign="top">
<td width="20%"><font size="2"><a href="Greg_couponpile.php?mc.cid=1">Apparel</a><br>
<a href="Greg_couponpile.php?Company=Dell">Arts / Collectibles</a><br>
<a href="Greg_Apple_2.php?Company=Dell">Auctions</a><br>
<a href="Greg_Apple_2.php?Company=Dell">Automotive</a><br>
<a href="Greg_Apple_2.php?Company=Dell">Baby / Maternity</a><br>
<a href="Greg_Apple_2.php?Company=Dell">Books / Magazines</a><br>
<a href="Greg_Apple_2.php?Company=Dell">Computer</a><br>
<a href="Greg_Apple_2.php?Company=Dell">Department Stores</a><br>
<a href="Greg_Apple_2.php?Company=Dell">Discount Goods</a><br>
<a href="Greg_Apple_2.php?Company=Dell">Educational</a><br>
<a href="Greg_Apple_2.php?Company=Dell">Electronics / Photo</a><br>
<a href="Greg_Apple_2.php?Company=Dell">Entertainment</a><br>
<a href="Greg_Apple_2.php?Company=Dell">Financial Services</a><br>
<a href="Greg_Apple_2.php?Company=Dell">Food / Drink</a><br>
<a href="Greg_Apple_2.php?Company=Dell">Flowers / Gifts</a><br>
<a href="Greg_Apple_2.php?Company=Dell">Health & Beauty</a><br>
<a href="Greg_Apple_2.php?Company=Dell">Home & Garden</a><br>
<a href="Greg_Apple_2.php?Company=Dell">Hobbies & Collectibles</a><br>
<a href="Greg_Apple_2.php?Company=Dell">Jewelry</a><br>
<a href="Greg_Apple_2.php?Company=Dell">Kitchen / Gourmet</a><br>
<a href="Greg_Apple_2.php?Company=Dell">Music / Video</a><br>
<a href="Greg_Apple_2.php?Company=Dell">Office / Business</a><br>
<a href="Greg_Apple_2.php?Company=Dell">Other</a><br>
<a href="Greg_Apple_2.php?Company=Dell">Pet Supplies</a><br>
<a href="Greg_Apple_2.php?Company=Dell">Phones / Wireless</a><br>
<a href="Greg_Apple_2.php?Company=Dell">Services</a><br>
<a href="Greg_Apple_2.php?Company=Dell">Shoes / Accessories</a><br>
<a href="Greg_Apple_2.php?Company=Dell">Sports / Fitness</a><br>
<a href="Greg_Apple_2.php?Company=Dell">Toys / Games</a><br>
<a href="Greg_Apple_2.php?Company=Dell">Travel / Luggage</a><br>
<a href="Greg_Apple_2.php?Company=Dell">Web Design</a><br>
<a href="Greg_Apple_2.php?Company=Dell">Web Hosting</a><br>
<a href="Greg_Apple_2.php?Company=Dell">Specialty</a><br><br>
</font></td>
<td width="58%"><!-- begin form--> <?php

# top of script
error_reporting(E_ALL);

// new connect
$dbh=mysql_connect ("localhost", "*****", "******") or die ('I cannot connect to the database because: ' . mysql_error());

// define the database you are going to use
mysql_select_db ("kujwnqqc_ewing");


// test if db works
// echo 'cid = '.$_GET["cid"];

$result = mysql_query ("SELECT name, offer_url, c_code
FROM merchant, mcat, offer
WHERE merchant.id = mcat.mid
AND merchant.id = offer.mid
AND mcat.cid = '$cid'
ORDER BY merchant.name");

// from greg but tweaked took out "m" and "o"
// define the mysql query you want to run
// $result = mysql_query ("SELECT name, offer_url, c_code
// FROM merchant, mcat, offer
// WHERE merchant_id = mcat_mid
// AND merchant_id = offer_mid
// AND mcat.cid = '".$mcat_cid."'
// ORDER BY merchant_name");

// greg original query
// SELECT m.name, o.offer_url, o.c_code
// FROM merchant m, mcat mc, offer o
// WHERE m.id = mc.mid
// AND m.id = o.mid
// AND mc.cid = 1
// ORDER BY m.name;


// a count query to tell the user how many results where found
// $count = mysql_query ("SELECT COUNT(*)
// FROM merchant
// WHERE '".$merchant_id."'");

// a count query to tell the user how many results where found
$count = mysql_query ("SELECT COUNT(*)
FROM merchant
WHERE id ");


// defines the countresult so we can display it later
$countresult = mysql_fetch_array($count);

// prints the number of results found
print "<center><font color=red><strong>".$countresult[0]."</strong></font> results found:<br><br></center>";

// simple loop to display all the results in the array
if ($row = mysql_fetch_array($result)) {

do {
print "<center><b>" . $row['name'] . "&nbsp;&nbsp;" . $row['offer_url'] . "&nbsp;&nbsp;" . $row['c_code'] . "&nbsp;&nbsp;" . "</b></center>" . "<br>\\n";
}

// do {
// print '<a href="http://' . $row['name'] . '"target=_blank>' . $row['name'] . "</a><br>\\n";
// }

while($row = mysql_fetch_array($result));
}
else {print "<center>We apologize, at this present time we do not have a coupon for this company.</center>";}

?> <!-- end form--></td>
<td width="22%"> <br>
<table width="100%" border="1" cellspacing="0" cellpadding="0" bordercolor="#000000" bordercolordark="#000000">
<tr>
<td><font face="Arial, Helvetica, sans-serif" size="1">Corner
Book Shelf for ____</font></td>
</tr>
<tr align="left" valign="top">
<td height="60">
<p><font size="2">book type 1<br>
book type 2<br>
book type 3<br>
book type 4<br>
book type 5<br>
book type 6<br>
book type 7<br>
book type 8</font></p>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td height="1" colspan="3"><img src="/images/black_line.gif" width="100%" height="1"></td>
</tr>
<tr>
<td height="20" colspan="3">
<div align="center"><font face="Arial, Helvetica, sans-serif" size="2"><a href="#">Legal
Terms</a>&nbsp;&nbsp;<a href="#">Copyright Info</a>&nbsp;&nbsp;<a href="#">Contact
Email</a><a href="#">&nbsp;&nbsp;Terms of Use</a>&nbsp;&nbsp;<a href="#">About
Us</a>&nbsp;&nbsp;<a href="#">Privacy Policy</a></font></div>
</td>
</tr>
<tr>
<td height="1" colspan="3"><img src="/images/black_line.gif" width="100%" height="1"></td>
</tr>
</table>




<edit>Saving your ass from hackers...</edit>

(Edited by WarMage on 05-01-2004 20:16)

WarMage
Maniac (V) Mad Scientist

From: Rochester, New York, USA
Insane since: May 2000

posted posted 05-02-2004 05:31

There are a number of things that I haven't seen before like

code:
$countresult = mysql_fetch_array($count);

print "<center><font color=red><strong>".$countresult[0]."</strong></font> results found:<br><br></center>";



I don't know how this is supposed to get you the number of lines... Why not just do

code:
print "<strong style="color:red;text-align:center">mysql_num_rows($count)</strong>"



Remember font has been deprecated, so you shouldn't use it. center is also an un-needed tag. CSS is key saves time an energy.

I have never seen an "if-do" statement before. Maybe this is something new. But to process results you would normally use a for or while loop.

code:
while($row = @mysql_fetch_array($count)){
print "<center><b>" . $row['name'] . "&nbsp;&nbsp;" . $row['offer_url'] . "&nbsp;&nbsp;" . $row['c_code'] . "&nbsp;&nbsp;" . "</b></center>" . "<br>\\n";
}



Your code needs a whole lot of work, and can be really simplified.

code:
//do the DB connection
//set up the query
$results = @mysql_query($sql);
if(@mysql_num_rows($results) == 0){
print "No results were found please try your query with different parameters.";
}
else{
while($row = @mysql_fetch_array($results)){
print "<center><b>" . $row['name'] . "&nbsp;&nbsp;" . $row['offer_url'] . "&nbsp;&nbsp;" . $row['c_code'] . "&nbsp;&nbsp;" . "</b></center>" . "<br>\\n";
}
}



I am not sure what is actually causing the blank page. If you could clarify or give a link that would be a good start. I am also not saying your code is wrong, I am just saying it is not the "standard" way of doing things.

You should also pay some attention to web standards, you might save yourself a whole lot of time, CSS is the server-side coder's dream.

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 05-02-2004 05:35

WarMage:

quote:
Remember font has been deprecated, so you shouldn't use it. center is also an un-needed tag.

In fact the CENTER tag is also deprecated.

norm
Paranoid (IV) Inmate

From: [s]underwater[/s] under-snow in Juneau
Insane since: Sep 2002

posted posted 05-02-2004 07:20

WarMage:

What you refered to as a ' if-do ' is actually a 'do while' loop inside of an if statement. I have seen this loop in books, but never seen it used before. Unless I'm mistaken a do while loop will execute once before checking the conditional, and then continue to loop if it evaluates as true.

I generally don't want anything to execute unless the conditional has already been evaluated.....so I've never felt the need to use this sort of loop.


CRO8:

This query has me confused:

code:
$count = mysql_query ("SELECT COUNT(*) 
FROM merchant
WHERE id ");



Shouldn't it be WHERE id='whatever' ?

I copied and pasted your code into my own PHP document and I do not get a blank page.The page displays top and side navigation, and the body of the page consists of your script echoing "I cannot connect to the database because: Access denied for user: '*****@localhost' (Using password: YES)", since I haven't built a database for this on my box. My point being - I do not get a blank page.

Are you getting a completely blank page, or do you get Top and Side navigation with only the body left blank? If it is the second case, my guess is that either you are not selecting the correct database or your queries are not returning any results. After all, if $row[0] contains nothing, nothing is exactly what PHP will print for you.

/* Sure, go ahead and code in your fancy IDE. Just remember: it's all fun and games until someone puts an $i out */

WarMage
Maniac (V) Mad Scientist

From: Rochester, New York, USA
Insane since: May 2000

posted posted 05-02-2004 15:08

Oh, if it was a do-while then that is a valid loop... I should take another look at the code. On my way out the door will look again later.

WarMage
Maniac (V) Mad Scientist

From: Rochester, New York, USA
Insane since: May 2000

posted posted 05-02-2004 17:25

You are very correct it is a do while loop, but being a do-while loop makes it a logic error. As it would do something with no data, then propagate the values. So your first row printed would be with "null" data. That is no good.

The code should really be cleaned up because with all of the comments flying it is really hard to read.

DL-44
Maniac (V) Inmate

From: under the bed
Insane since: Feb 2000

posted posted 05-02-2004 17:42

Are youtalking about a totally blank page - like all your links, and the table itself, and everything else is totally missing?

Or just that your Data from the Database is missing?

Those would be two very distinctly different problems, and while your php/sql could use some work, that's not going to help if there is some other problem preventing the page from displaying.

You've only given us the table portion of the code - what does the rest of the code for the page look like?


Do you have this page online somewhere?

CRO8
Bipolar (III) Inmate

From: New York City
Insane since: Jul 2000

posted posted 05-02-2004 17:44

hey guys- thanks for combing thru the code. B/c Im relatively new to php/mysql I left comments in from a past project just so I have as a reference. Once I get this to process correctly I will definitely clean up my code, eliminate comments, etc.

This is the html page, click on Apparel and you'll get the blank php page.

(Edited by CRO8 on 05-02-2004 17:47)

WarMage
Maniac (V) Mad Scientist

From: Rochester, New York, USA
Insane since: May 2000

posted posted 05-02-2004 19:27

I don't get a blank page. I get 37 items found.

norm
Paranoid (IV) Inmate

From: [s]underwater[/s] under-snow in Juneau
Insane since: Sep 2002

posted posted 05-02-2004 19:37

It does indeed look like http://www.couponpile.com/Greg_couponpile_2.php is blank.

But where can we see the source code for http://www.couponpile.com/Greg_couponpile_2.php ?
Why would we want to see the page that links to the problem page?

If the code you posted earlier is part of the above referenced URL, I can tell you that your will not return any results because you are not handling any $_GET variables from the URL.

As far as your page not displaying at all, here is what I would do:

Comment out all of the code inside the PHP tags and add echo "<font color='red'>Works</font>";

Then you can begin the process of moving the start of the comment block down, one PHP statement at a time and placing the above echo statement in an if block to see if the newly uncommented statement executes. It should be quickly appearent where your script breaks using this process.

/* Sure, go ahead and code in your fancy IDE. Just remember: it's all fun and games until someone puts an $i out */

WarMage
Maniac (V) Mad Scientist

From: Rochester, New York, USA
Insane since: May 2000

posted posted 05-02-2004 19:48

Still not blank for me, might be an internet explorer thing. The page is rendering in quirks mode though.

Your page is missing a Document Type, but it does have the character encoding.

Your lists should be in lists using CSS to get rid of the text-decoration and such. The extensive use of <br> is striking.

It is a table hacked nightmare and I am seriously out of practice reading table code and turning it into a web page in my head so I am not exactly sure what the problem might be.

However, since I can see the page and others can not, this is not a server side issue but an HTML issue, and your HTML is terrible.

I tried to validate the page, and the glaring error in big red letters is that it is missing a doctype, which I already stated. I then manually set it to HTML 4.01 and it wasn't terrible. The one error that I see that maybe IE will choke on is BORDERCOLORDARK on line 106. I have never ever seen this attribute before, even in the most browser specific quirky code.

You should really look into using CSS and try validating your page yourself. http://validator.w3.org/

Good luck.

norm
Paranoid (IV) Inmate

From: [s]underwater[/s] under-snow in Juneau
Insane since: Sep 2002

posted posted 05-02-2004 19:51

Well I now find that I get the same results as WarMage; if I use Mozilla. I'm on a Mac, and Safari displays Greg_couponpile_2.php as a blank page and IE won't even display the starting Greg_testpage.htm, and Opera displays part of each page.

So I guess we are now looking for HTML problems.......

/* Sure, go ahead and code in your fancy IDE. Just remember: it's all fun and games until someone puts an $i out */

CRO8
Bipolar (III) Inmate

From: New York City
Insane since: Jul 2000

posted posted 05-03-2004 02:06

ok just got back . . . WArmage thanks for ****** out my logon/password. Rookie mistake. I will throw my html into the validator and see where the problem lies.

Thanks guys.

CRO8
Bipolar (III) Inmate

From: New York City
Insane since: Jul 2000

posted posted 05-03-2004 03:33

Norm- yup I did revise this and get 37 results. Thanks.

$count = mysql_query ("SELECT COUNT(*)
FROM mcat
WHERE cid = 1");


I validated my html and css code and still get a blank page thru my html page (click apparel)

Let me read thru the other responses so I can answer all questions . . .

Thanks again.

« BackwardsOnwards »

Show Forum Drop Down Menu