General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old March 28th, 2004, 04:06 AM
Pheifel Pheifel is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Location: Denmark
Posts: 174 Pheifel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 43 m 46 sec
Reputation Power: 5
Send a message via MSN to Pheifel
Odd and even

Hey. I need to be able do difference between odd and even id numbers (from a db) whats the php code fore this ?

Reply With Quote
  #2  
Old March 29th, 2004, 09:50 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
If you're doing your ids as auto_increments, the difference will always be either one or zero. If that doesn't help, you'll have to be a little more specific about what you want to know.
__________________
Please don't PM me asking for solutions outside the scope of a thread.
Keeping all responses in a thread stands to help others who come along later,
which is after all what this forum's all about.

Reply With Quote
  #3  
Old March 29th, 2004, 03:51 PM
Pheifel Pheifel is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Location: Denmark
Posts: 174 Pheifel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 43 m 46 sec
Reputation Power: 5
Send a message via MSN to Pheifel
specified

Yes, the id is auto increased. But i need to be able to sort by od or even id numer. ei. odd id goes on the right, even id goes on the left. is there a function, that reconises whether the id is odd or even ?

Reply With Quote
  #4  
Old March 29th, 2004, 04:24 PM
tobycloud tobycloud is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Location: Near Albany NY
Posts: 27 tobycloud User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to tobycloud Send a message via AIM to tobycloud
I had a kind of solution to this.

Code:
<?php
  $test_result = $test_num / 2;

  if(is_int($test_result)) 
	echo "This number is even";
  else
	echo "This number is odd";
?>


But of course Data Type Int has restrictions.

Oh yeah by the way, this is a cheap solution.

Reply With Quote
  #5  
Old March 30th, 2004, 06:26 AM
crudesys crudesys is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Location: California
Posts: 25 crudesys User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Lightbulb re: odd-even

<TABLE BORDER=1>
<TR>
<TH>ODD</TH>
<TH>EVEN</TH>
</TR>
<?
$odd_counter = 0;
$even_counter = 0;

while ($id_array=mysql_fetch_array($result))
{
// *** even number *** //
if ($id_array['id'] % 2 == 0)
{
$even_array[$even_counter] = $id_array['id'];
$even_counter++;
}
// *** odd number *** //
else
{
$odd_array[$odd_counter] = $id_array['id'];
$odd_counter++;
}
}

// *** get larger counter variable *** //
$counter = ($even_counter > $odd_counter) ? $even_counter : $odd_counter;

// *** separate odd and even id's *** //
for($ctr=0;$ctr<$counter;$ctr++)
{
?>
<TR>
<TD><? print ($odd_array[$ctr]); ?></TD>
<TD><? print ($even_array[$ctr]); ?></TD>
</TR>
<?
}
?>
</TABLE>


i hope this idea helps.

crudesys

Reply With Quote
  #6  
Old March 30th, 2004, 08:21 AM
Pheifel Pheifel is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Location: Denmark
Posts: 174 Pheifel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 43 m 46 sec
Reputation Power: 5
Send a message via MSN to Pheifel
Hmmm.... that was a bit more complicatet than i had expected. I dont understand the part where u suddently get a $ctr in there.... where did that come from ?!...

- Pheifel

Reply With Quote
  #7  
Old March 30th, 2004, 11:53 AM
crudesys crudesys is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Location: California
Posts: 25 crudesys User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
the $ctr variable is just my idea of going through the odd_array and the even_array members. $ctr is used as the index and increments until $counter is reached. that would go through each member of each array.

did you try the code?

Reply With Quote
  #8  
Old March 30th, 2004, 05:41 PM
Pheifel Pheifel is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Location: Denmark
Posts: 174 Pheifel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 43 m 46 sec
Reputation Power: 5
Send a message via MSN to Pheifel
i have implimentet it... but im still working to make it function :S it doesnt seem to work.. :S... im still trying to figure it out... im getting at a result thnx

Reply With Quote
  #9  
Old March 30th, 2004, 06:00 PM
crudesys crudesys is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Location: California
Posts: 25 crudesys User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
ok. just let me know if you have problems. i tried it with sample data and it worked for me

good luck

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Odd and even


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT