Jump to content

better way to do this??


acidglitter

Recommended Posts

This is a temporary page on my site.. I'm trying to reorganize the articles..

http://www.vanillaeyeliner.com/temp.php

 

This is the code for that page that I was changing around tonight.. its a mess and I got too sick of it to make it completely work...

 

echo "<h1>Articles</h1>
<table cellspacing=\"0\" cellpadding=\"0\" width=\"100%\">
<tr><td><h2 style=\"margin:0!important;\">Shopping Around</h2></td>
<td><h2 style=\"margin:0!important;\">Getting Gorgeous Skin</h2></td></tr>";

$onlyonce=0;
$msql=mysql_query("SELECT id,title,class FROM tutorials WHERE type='article' ORDER BY class DESC, id DESC");
while($mrow=mysql_fetch_array($msql)){
if($mrow['class']==shopping){
	$onlyonce++;
	if($onlyonce==1){
		echo "<tr><td valign=\"top\" style=\"padding:3px;width:280px;\"><p>";
	}

	echo "<a href=\"articles.php?aid={$mrow['id']}\">{$mrow['title']}</a>";
	$thetutid=$mrow['id'];
	$q=mysql_query("SELECT date,IF((NOW() - INTERVAL 7 DAY) < date, 1, 0) AS `NewPost` FROM tutorials WHERE id='$thetutid'");
	while($row=mysql_fetch_assoc($q)){
	if($row["NewPost"]==1){
		echo " <b style=\"color:#FF277D;\">new!</b>";
	}}
	echo "<br />\n";
} elseif($mrow['class']==prettyskin){
	$onlyonce++;
	if($onlyonce==1){
		echo "</p></td>
		<td valign=\"top\" style=\"padding:3px;\"><p>";
	}

	echo "<a href=\"articles.php?aid={$mrow['id']}\">{$mrow['title']}</a>";
	$thetutid=$mrow['id'];
	$q=mysql_query("SELECT date,IF((NOW() - INTERVAL 7 DAY) < date, 1, 0) AS `NewPost` FROM tutorials WHERE id='$thetutid'");
	while($row=mysql_fetch_assoc($q)){
	if($row["NewPost"]==1){
		echo " <b style=\"color:#FF277D;\">new!</b>";
	}}
	echo "<br />\n";
} elseif($mrow['class']==howto){
	$onlyonce++;
	if($onlyonce==1){
		echo "</p></td></tr>
		<tr><td><h2 style=\"margin:0!important;\">Basic How-to's</h2></td>
		<td></td></tr>
		<tr><td valign=\"top\" style=\"padding:3px;\"><p>";
	}

	echo "<a href=\"articles.php?aid={$mrow['id']}\">{$mrow['title']}</a>";
	$thetutid=$mrow['id'];
	$q=mysql_query("SELECT date,IF((NOW() - INTERVAL 7 DAY) < date, 1, 0) AS `NewPost` FROM tutorials WHERE id='$thetutid'");
	while($row=mysql_fetch_assoc($q)){
	if($row["NewPost"]==1){
		echo " <b style=\"color:#FF277D;\">new!</b>";
	}}
	echo "<br />\n";
}
}
echo "</p></td><td></td></tr></table><br />";

 

 

I want to be able to just have the code that displays the links once... I tried using functions, and just changing the class name to show different article links, but I couldn't get that to work right.. Does anyone know a much better, faster way I could do this?

Link to comment
Share on other sites

  • 1 year later...

Solution for people who are still interested, better late than never, this is how you do this easily and it works no matter how many type you have in your DB or whether you add more or remove some...

 

SQL QUERY OF PRODUCTS DATABASE

$typestore=$SQL['type']; //needs to be external from while command

$display.="<html>";
$display.=SET THE INITIAL TYPE HEADING HTML;

WHILE COMMAND
{
if($typestore==$type){
$typestore=$type;
$display.="DYNAMIC HTML FOR PRODUCT";
}else{
$typestore=$type;
$display.="HTML FOR NEW CATEGORY";
$display.="DYNAMIC HTML FOR PRODUCT";
}
}

$display.="</html>";

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.