Working on a function that prints out all database rows that end with _n where n is single digit number 1 - 9 first and then prints rows that do not end in _n. So far I have been trying to use this code
$theQuery="SELECT * FROM tableContent"
while($row=mysql_query($theQuery))
{
if(substr($row[0],-2,1)=="_")
{
//DO WHAT IT DOES FOR this_1, this_2, this_3 first
}
}
while($row=mysql_query($theQuery))
{
if(substr($row[0],-2,1)!="_")
{
//DO WHAT IT DOES FOR this, that, andWHatHaveYou afterwords
}
}
I don't know why the !="_" doesn't get done.
This is the exact code I have implemented but doesnt work 100%
$query="SELECT * FROM rt_content";
$contents=mysql_query($query);
if($contents)
{
$baseSection = (substr($row[0],-2,-1)=="_")? substr($row[0],0,-2):$row[0];
echo "<table class=\"lined\" style=\"width:100%\"><tr><td class=\"lined\">options</td><td class=\"lined\">contentName</td><td class=\"lined\">en</td><td class=\"lined\">es</td></tr>\n";
while( $row=mysql_fetch_array($contents,MYSQL_NUM) )
{
if( substr($row[0],-2,1)=="_" )
{
echo "<tr><td class=\"lined\"><a href=\"admin.html?content=edit;".$baseSection."\">EDIT</a></td><td class=\"lined\"><a href=\"admin.html?content=view;".$baseSection."\">".$row[0]."</a></td><td class=\"lined\">".$row[1]."</td><td class=\"lined\">".$row[2]."</td></tr>\n";
}
}
while( $row=mysql_fetch_array($contents,MYSQL_NUM) )
{
if( substr($row[0],-2,1)!="_" )
{
echo "<tr><td class=\"lined\"><a href=\"admin.html?content=edit;".$baseSection."\">EDIT</a></td><td class=\"lined\"><a href=\"admin.html?content=view;".$baseSection."\">".$row[0]."</a></td><td class=\"lined\">".$row[1]."</td><td class=\"lined\">".$row[2]."</td></tr>\n";
}
}
echo "</table>\n";
}
Does anyone see anything wrong with this or can do it better?