PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 10th, 2013, 07:10 AM
pkevin pkevin is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 5 pkevin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 21 m 10 sec
Reputation Power: 0
Problem with Div's

I'm trying to create div's dynamically, say every 5 rows. I can do this, but not when I add the rest of the code i'm using (menu script). My code is below,

PHP Code:
function display_children($parent$level) {     $result mysql_query("SELECT a.id, a.label, a.link, Deriv1.Count FROM `menu` a  LEFT OUTER JOIN (SELECT parent, COUNT(*) AS Count FROM `menu` GROUP BY parent) Deriv1 ON a.id = Deriv1.parent WHERE a.parent=" $parent);

$count 0;          

echo 
'<div>';     
echo 
"<ul id='menu'>";          
while (
false !== ($row mysql_fetch_array($result))) {                                             if ($row['Count'] > 0) {             
echo 
"<li><a href='" $row['link'] . "'>" $row['label'] . "</a>";             
display_children($row['id'], $level 1);             
echo 
"</li>";        
 } elseif (
$row['Count']==0) {             
echo 
"<li><a href='" $row['link'] . "'>" $row['label'] . "</a></li>";
         } else;
     }           

++
$count; if (($count 5) == 0) { 
    echo 
"</ul>";     echo "</div><div>";
   }      
}               

display_children(01); 


Please help can't work it out,

Reply With Quote
  #2  
Old January 10th, 2013, 07:25 AM
gw1500se gw1500se is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,886 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 2 Weeks 3 Days 8 h 22 m 27 sec
Reputation Power: 581
Please edit your post and enclose your code in [ PHP ] tags. See the sticky at the top of this forum.
__________________
There are 10 kinds of people in the world. Those that understand binary and those that don't.

Reply With Quote
  #3  
Old January 10th, 2013, 07:52 AM
gw1500se gw1500se is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,886 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 2 Weeks 3 Days 8 h 22 m 27 sec
Reputation Power: 581
1) Don't use the deprecated mysql extensions. Switch to PDO.
2) You don't say specifically what the problem is but I can see that you end </ul>, end </div> and start <div> but you are not starting <ul> again.

Reply With Quote
  #4  
Old January 10th, 2013, 08:28 AM
pkevin pkevin is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 5 pkevin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 21 m 10 sec
Reputation Power: 0
Quote:
Originally Posted by gw1500se
1) Don't use the deprecated mysql extensions. Switch to PDO.
2) You don't say specifically what the problem is but I can see that you end </ul>, end </div> and start <div> but you are not starting <ul> again.




I'm trying to achieve having say 5 records returned for every <Div>

Reply With Quote
  #5  
Old January 10th, 2013, 08:36 AM
gw1500se gw1500se is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,886 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 2 Weeks 3 Days 8 h 22 m 27 sec
Reputation Power: 581
So what are you getting and what is wrong?

Reply With Quote
  #6  
Old January 10th, 2013, 09:00 AM
pkevin pkevin is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 5 pkevin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 21 m 10 sec
Reputation Power: 0
Quote:
Originally Posted by gw1500se
So what are you getting and what is wrong?


Each div is a page in a jquery flip book. I want to use a database driven menu system for the index pages, in the flip book.

this basic code works and returns 2 records per div

PHP Code:
 $con mysql_connect("localhost","user","pass");
if (!
$con)
  {
  die(
'Could not connect: ' mysql_error());
  }

mysql_select_db("my_tbl"$con);

$result mysql_query("SELECT * FROM poop");

$count 0;


echo 
'<div style="border: thin solid #333;">'
while (
false !== ($row mysql_fetch_array($result)))
  {
      
  
//echo '<div style="border: thin solid #333;">'; 
  
echo $row['id'] . " " $row['text']; 
  
?>
  <a href="<?php echo $row['link']; ?>"><?php echo $row['text']; ?></a>
  
  <?php
  
echo "<br />";
  
  
   ++
$count;
  if ((
$count 2) == 0) {
    echo 
'</div><div style="border: thin solid #333;">';
    
  }
 }

mysql_close($con); 



but when I add the menu it the divs get broken ( current attempt)

PHP Code:
function display_children($parent$level) {
    
$result mysql_query("SELECT a.id, a.label, a.link, Deriv1.Count FROM `menu` a  LEFT OUTER JOIN (SELECT parent, COUNT(*) AS Count FROM `menu` GROUP BY parent) Deriv1 ON a.id = Deriv1.parent WHERE a.parent=" $parent);
    
    
    
$count 0;
    
$count_b 0;

    ++
$count_b;
if ((
$count_b 1) == 1) {
    
    echo 
"<div>";    
        
    }
        
    while (
false !== ($row mysql_fetch_array($result))) {
        
        echo 
"<ul>";
        if (
$row['Count'] > 0) {
            echo 
"<li><a href='" $row['link'] . "'>" $row['label'] . "</a>";
            
display_children($row['id'], $level 1);
            echo 
"</li>";
            } elseif (
$row['Count']==0) {
            echo 
"<li><a href='" $row['link'] . "'>" $row['label'] . "</a></li>";
        } else;
        
        echo 
"</ul>";

  }
                
    ++
$count;
if ((
$count 2) == 0) {
    
    echo 
"</div>";    
        
    }    
    
}

display_children(01);

mysql_close($con); 


returns 5 pages, first has 1 record returned, page 2 has 5 records returned and the rest one each.

Reply With Quote
  #7  
Old January 10th, 2013, 09:10 AM
gw1500se gw1500se is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,886 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 2 Weeks 3 Days 8 h 22 m 27 sec
Reputation Power: 581
Using recursive routines can be tricky. It appears that you are generating divs within divs. Is that what you want? What does the resulting HTML source look like?

Reply With Quote
  #8  
Old January 10th, 2013, 09:18 AM
pkevin pkevin is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 5 pkevin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 21 m 10 sec
Reputation Power: 0
Quote:
Originally Posted by gw1500se
Using recursive routines can be tricky. It appears that you are generating divs within divs. Is that what you want? What does the resulting HTML source look like?



HTML source is

<ul><li><a href='#home'>Home</a></li></ul><ul><li><a href='#code'>Code</a><ul><li><a href='#php'>PHP</a></li></ul><ul><li><a href='#css'>Css</a></li></ul><ul><li><a href='#scripts'>Scripts</a></li></ul><ul><li><a href='#help'>Help</a></li></ul></li></ul><ul><li><a href='#contact'>Contact</a></li></ul><ul><li><a href='#archive'>Archive</a></li></ul><ul><li><a href='#snippet'>Snippet</a></li></ul>

Reply With Quote
  #9  
Old January 10th, 2013, 09:43 AM
gw1500se gw1500se is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,886 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 2 Weeks 3 Days 8 h 22 m 27 sec
Reputation Power: 581
No div's are being output at all. Obviously the problem is your 'if' blocks that are intended to generate them. Your 'count' variables are pretty much useless. You can eliminate them, including the 'if' blocks. They will always be 1. Its my guess that you really don't want to reinitialize them to 0 each time the function is called. You probably want to initialize them to 0 outside the function and then pass them to each call to be incremented and tested.

Reply With Quote
  #10  
Old January 10th, 2013, 11:49 AM
pkevin pkevin is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 5 pkevin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 21 m 10 sec
Reputation Power: 0
Using recursive routines can be tricky, your so right. I think I'll try a different approach, and display the content in a different manor.

Thanks for helping, have learned a lot from you, will help others in this forum if I can.

Kevin.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Problem with Div's

Developer Shed Advertisers and Affiliates



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 | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap