which datatype?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
jamrop
Forum Commoner
Posts: 80
Joined: Fri May 16, 2003 5:38 pm

which datatype?

Post by jamrop »

Hey

Wondering if anyone can help

I have a table which has an anime name, ep start and ep end

anime name is varchar
ep start is int
ep end is int

When i insert in a new anime titles, and if there is not an ep end, say there is only 1 episode, andI leave ep end blank, but when i get the results of anime titles, i always get a 0 in ep end, is there a way to stop this, or another data type i should use to leave it blank?

many thanks
User avatar
coolpravin
Forum Newbie
Posts: 20
Joined: Mon May 19, 2003 12:56 am
Location: India

But why to change

Post by coolpravin »

But why youi want to change that man !!!!!
You can consider this 0 as blank.
Hence whenever you find it 0 consider it as blank.
Otherwise you can use varchar here also.
I know you may want to use

ep end =ep start
when your ep end is balnk.
Hence when it is zero use this
and thats all.Because int is always better to manipulate with numbers.
Hence i will insist on to use int.
:wink:
jamrop
Forum Commoner
Posts: 80
Joined: Fri May 16, 2003 5:38 pm

Post by jamrop »

ok thanks for that, but how would i stop it from showing 0 in php

I am listing all the anime, and i get

naruto 1 - 0

instead i want it

naruto 1

many thanks
User avatar
coolpravin
Forum Newbie
Posts: 20
Joined: Mon May 19, 2003 12:56 am
Location: India

Just replace before echo

Post by coolpravin »

Ok.Just try to replace it with blank before echo.
I am listing all the anime, and i get
naruto 1 - 0
instead i want it
naruto 1
if suppose thsi is your code

Code: Select all

<?php
$start=$row["ep_start"];
$end=$row["ep_end"];
echo"naruto ".$start."-".$end;
?>
Then now use this one

Code: Select all

<?php
$start=$row["ep_start"];
$end=$row["ep_end"];
if(!$end)
   $end="";
echo"naruto ".$start."-".$end;
?>
And this will work well.
Please clarufy is it working or not.?
jamrop
Forum Commoner
Posts: 80
Joined: Fri May 16, 2003 5:38 pm

Post by jamrop »

hey

i have been thinking how to integrate that code in but i am getting confused

here is my code for displaying anime

Code: Select all

<?php

$sql = 'SELECT * FROM anime order by Anime_Name' ; 


$rs=mysql_query($sql,$db);
$numofrows =mysql_num_rows($rs);

?>
<?php
for ($x = 0; $x <$numofrows;  $x++)
{


$row = mysql_fetch_array($rs);

	
	
	
	    
	if($x % 2)
	{
	echo "<tr bgcolor="white">\n";
	}
	else
	{
	echo "<tr bgcolor ="green">\n";
	}
	?>
                <td bgcolor="#FFFFCC"><font size="-1"><?php echo $row['Anime_name']; ?></td>
                <td><font size="-1"><?php echo $row['Ep_Start']; ?> - <font size="-1"><?php echo $row['EP_End']; ?></td>
                <td align="center"><font size="-1"><?php echo $row['Language']; ?></td>
                <td align="center"><font size="-1"><?php echo $row['Complete']; ?></td>
                <td align="center"><font size="-1"><?php echo $row['Discs']; ?></td>
                <td align="center"><font size="-1"><?php echo $row['Formats']; ?></td>
                <td align="center"><font size="-1"><?php echo $row['Quality']; ?></td>
                <td align="center"><font size="-1"><a href="detail.php?Anime_id=<?php echo $row['Anime_id'];?> ">Info</a></td>
                <?php	
}

?>
It is displaying all my anime titles, so
thinking abuot the code u put, if i put at the top

Code: Select all

<?php 
$start=$row["ep_start"]; 
$end=$row["ep_end"]; 
?>
but as for the rest, i am not sure how to imply that

so the bottom bit

Code: Select all

<?php

if(!$end) 
   $end=""; 
echo"naruto ".$start."-".$end; 
?>
is saying that if ep end equals nothing then put naruto start - end?

or

is it saying that if ep end equals something than 0 then put naruto start -end


Sorry i am just trying to understand

?>
User avatar
coolpravin
Forum Newbie
Posts: 20
Joined: Mon May 19, 2003 12:56 am
Location: India

Correct

Post by coolpravin »

Yes you are very correct
now just replace your

Code: Select all

<td><font size="-1"><?php echo $row['Ep_Start']; ?> - <font size="-1"><?php echo $row['EP_End']; ?></td>

with

Code: Select all

<td><font size="-1"><?php echo $start ; ?> - <font size="-1"><?php echo $end; ?></td>

Thats it
jamrop
Forum Commoner
Posts: 80
Joined: Fri May 16, 2003 5:38 pm

Post by jamrop »

My hosting server is down atm, so i can not test it,

but if i put this

Code: Select all

<?php
$sql = 'SELECT * FROM anime order by Anime_Name' ; 


$rs=mysql_query($sql,$db);
$numofrows =mysql_num_rows($rs);

?>
<?php
for ($x = 0; $x <$numofrows;  $x++)
{


$row = mysql_fetch_array($rs);

	
$start=$row["Ep_Start"]; 
$end=$row["EP_End"]; 

	
	    
	if($x % 2)
	{
	echo "<tr bgcolor="white">\n";
	}
	else
	{
	echo "<tr bgcolor ="white">\n";
	}
	if(!$end) 
   $end="";
	?>
                <td bgcolor="#FFFFCC"><font size="-1"><?php echo $row['Anime_name']; ?></td>
                <td><font size="-1"><?php echo $start; ?> - <font size="-1"><?php echo $end; ?></td>
                <td align="center"><font size="-1"><?php echo $row['Language']; ?></td>
                <td align="center"><font size="-1"><?php echo $row['Complete']; ?></td>
                <td align="center"><font size="-1"><?php echo $row['Discs']; ?></td>
                <td align="center"><font size="-1"><?php echo $row['Formats']; ?></td>
                <td align="center"><font size="-1"><?php echo $row['Quality']; ?></td>
                <td align="center"><font size="-1"><a href="detail.php?Anime_id=<?php echo $row['Anime_id'];?> ">Info</a></td>
                <?php	
}
?>
it should work?

Many thanks
?>
jamrop
Forum Commoner
Posts: 80
Joined: Fri May 16, 2003 5:38 pm

Post by jamrop »

Thanks

For worked gr8

Just one thing tho

what if i wanted

if they is an ep end

naruto 1 - 2

if there is no ep end

and i wanted just
naruto 1

not having the -

How would i stop that from displaying?

many thanks
User avatar
coolpravin
Forum Newbie
Posts: 20
Joined: Mon May 19, 2003 12:56 am
Location: India

Just do this

Post by coolpravin »

Instead of

Code: Select all

<?php
  if(!$end) 
   $end=""; 
?>
use

Code: Select all

<?php
if($end) 
   $end=" - ".$end; 
else
	$end="";

?>
And In place of

Code: Select all

<?php
<td><font size="-1"><?php echo $start; ?> - <font size="-1"><?php echo $end; ?></td> 
?>
Use

Code: Select all

<?php
<td><font size="-1"><?php echo $start; ?> <?php echo $end; ?></td> 

?>
Is it worked?
jamrop
Forum Commoner
Posts: 80
Joined: Fri May 16, 2003 5:38 pm

Post by jamrop »

thanking you
Post Reply