SitePoint Sponsor

User Tag List

Page 2 of 3 FirstFirst 123 LastLast
Results 26 to 50 of 68
  1. #26
    Non-Member
    Join Date
    Oct 2009
    Posts
    1,852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you have to add some conditions to this code.
    to output category title only if it was changed

  2. #27
    SitePoint Wizard
    Join Date
    Dec 2005
    Posts
    1,675
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what sort of conditions? your probably getting feed up with this thread now Shrapnel_N5, I do appreciate the help thanks
    The more you learn.... the more you learn there is more to learn.

  3. #28
    Non-Member
    Join Date
    Oct 2009
    Posts
    1,852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sort of
    it looks like your task far beyond your knowledge
    And I don't feel like to write entire application for you

  4. #29
    SitePoint Wizard
    Join Date
    Dec 2005
    Posts
    1,675
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    a long day if you can just get us started, and I'll see if I can finish the rest myself, maybe continue tomorrow if I have any problems with a fresh head
    The more you learn.... the more you learn there is more to learn.

  5. #30
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,048
    Mentioned
    16 Post(s)
    Tagged
    3 Thread(s)
    PHP Code:
    <?php
    $arrVenues 
    = array(
        array(
    'category_id'=>5,'category'=>'Bars','venue'=>'venue1','venue_id'=>3)
        ,array(
    'category_id'=>5,'category'=>'Bars','venue'=>'venue2','venue_id'=>34)
        ,array(
    'category_id'=>45,'category'=>'Clubs','venue'=>'venue3','venue_id'=>87)
        ,array(
    'category_id'=>45,'category'=>'Clubs','venue'=>'venue4','venue_id'=>921)
        ,array(
    'category_id'=>21,'category'=>'Something Else','venue'=>'venue45','venue_id'=>324)
        ,array(
    'category_id'=>48,'category'=>'Something Else 2','venue'=>'venue12','venue_id'=>1213)
    );

    $intCategory null;
    foreach(
    $arrVenues as $arrVenue) {

        if(
    $intCategory != $arrVenue['category_id']) {
            if(
    $intCategory !== null) echo '</ul></div>';
            echo 
    '<div><h2>',$arrVenue['category'],'</h2><ul>';
            
    $intCategory $arrVenue['category_id'];
        }

        echo 
    '<li>',$arrVenue['venue'],'</li>';
    }
    ?>

  6. #31
    SitePoint Wizard
    Join Date
    Dec 2005
    Posts
    1,675
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks oddz

    So what do the numbers mean and exactly whats happening here?

    array('category_id'=>45 ?
    The more you learn.... the more you learn there is more to learn.

  7. #32
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,048
    Mentioned
    16 Post(s)
    Tagged
    3 Thread(s)
    That would be a fake result set to replaced by the an actual result set.

    The rest of code is used to iterate the result set and output valid html without missing closing or opening elements.

    When the loop begins no category exists which is identified by $intCategory being null.

    Upon iteration the last category is checked for equality with the current rows category. When the category is not the same the new category is printed out and the previous div and ul is closed. After which the current category is set to that rows category and the venue is printed out. The first line in the condition makes sure that the first row never has closing elements printed out. If the item is first nothing is before it, thus no need to close an element that doesn't exist.

  8. #33
    SitePoint Wizard
    Join Date
    Dec 2005
    Posts
    1,675
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cheers oddz, Ill try an digest this tomorrow, bit late me now thanks again
    The more you learn.... the more you learn there is more to learn.

  9. #34
    SitePoint Wizard
    Join Date
    Dec 2005
    Posts
    1,675
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you about Shrapnel_N5. What do you think off oddz post?

    array('category_id'=>5,'category'=>'Bars','venue'=>'venue1','venue_id'=>3)

    venue1 (does he mean type in all the venues manual? What do the numbers at the end mean?)

    Cheers CB
    The more you learn.... the more you learn there is more to learn.

  10. #35
    Non-Member
    Join Date
    Oct 2009
    Posts
    1,852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It is merely an example. To understand and devise further.
    He wrote this array to substitute one you getting from the database.
    So, you just have to use your own instead of oddz's one.

  11. #36
    SitePoint Wizard
    Join Date
    Dec 2005
    Posts
    1,675
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I see. I'll try and get my head around it, thanks again
    The more you learn.... the more you learn there is more to learn.

  12. #37
    Non-Member
    Join Date
    Oct 2009
    Posts
    1,852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I hope you sorted things out.
    But just to be sure.
    You need ONE query to gel ALL venues. Without all these trims, str_replaces and other ridiculous stuff. Without even WHERE clause.
    One plain and simple query that lists all venues. Ordered by category.
    Once you get all it's rows into array, you can use oddz's code to output it in the way you want it. I didn't check this code yet but it looks like usable one

  13. #38
    SitePoint Wizard
    Join Date
    Dec 2005
    Posts
    1,675
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is this what you mean?

    Code MySQL:
    $arrVenues = ("SELECT category_id, venue_id FROM tbl_venues ORDER BY category_id", ARRAY_A);

    So how do I can display the output then below?
    Code PHP:
    <? if($num_rows4): ?>
    <ul>
    <? foreach($DATA3 as $row4): ?>
     
    <li></li>
     
    <? endforeach ?>
    </ul>

    Any help or direction would be great, thanks
    The more you learn.... the more you learn there is more to learn.

  14. #39
    Non-Member
    Join Date
    Oct 2009
    Posts
    1,852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    your ***_id always confuse me. because term id used in the mysql for the numeric identifiers.

    but if you have all necessary data with this query, you can use oddz's code now for output it.

  15. #40
    SitePoint Wizard
    Join Date
    Dec 2005
    Posts
    1,675
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Shrapnel_N5, "...always confuse me" everyone has there own way

    Code MySQL:
    $arrVenues = ("SELECT category_id, venue_id FROM tbl_venues ORDER BY category_id", ARRAY_A);

    Code PHP:
    $intCategory = null;
    foreach($arrVenues as $arrVenue) {
     
        if($intCategory != $arrVenue['category_id']) {
            if($intCategory !== null) echo '</ul></div>';
            echo '<div><h2>',$arrVenue['category'],'</h2><ul>';
            $intCategory = $arrVenue['category_id'];
        }
     
        echo '<li>',$arrVenue['venue'],'</li>';
    }

    I'll give this a try and get back to you
    The more you learn.... the more you learn there is more to learn.

  16. #41
    SitePoint Wizard
    Join Date
    Dec 2005
    Posts
    1,675
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Warning: Invalid argument supplied for foreach() in ... 294

    Code PHP:
    		foreach($arrVenues as $arrVenue)  // line294

    As in the code above, whats causing this?
    The more you learn.... the more you learn there is more to learn.

  17. #42
    Non-Member
    Join Date
    Oct 2009
    Posts
    1,852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    actually this code
    $arrVenues = ("SELECT category_id, venue_id FROM tbl_venues ORDER BY category_id", ARRAY_A);
    does assign a string to $arrVenues variable

  18. #43
    SitePoint Wizard
    Join Date
    Dec 2005
    Posts
    1,675
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Shrapnel, so what are you saying? Do I need to remove something?
    The more you learn.... the more you learn there is more to learn.

  19. #44
    Non-Member
    Join Date
    Oct 2009
    Posts
    1,852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To add I'd say.
    Do you know what to do with SQL queries? Do you have any in your scripts?
    Why not to do the same with this one?

  20. #45
    SitePoint Wizard
    Join Date
    Dec 2005
    Posts
    1,675
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do you know what to do with SQL queries? Do you have any in your scripts?
    Isn't that what we've been doing for the past 2 nights? I'm familiar with SQL, are you saying revert back to the original method: keep our new select statement and output the results the same as all the other scripts?

    output example from previous script:

    Code PHP:
    <? if($num_rows4): ?>
    			<ul>
    		<? foreach($DATA3 as $row4): ?>
     
    				<li></li>
     
    		<? endforeach ?>
    			</ul>
    		<? else: ?>
    		 <p>No data found</p>
    		<? endif ?>

    Correct or am I missing something here Shrapnel?
    The more you learn.... the more you learn there is more to learn.

  21. #46
    Non-Member
    Join Date
    Oct 2009
    Posts
    1,852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You have an SQL query in the $arrVenues variable.
    This query needs to be assigned to another variable. Call it $sql
    Then executed.
    And results assigned to $arrVenues array.

    Now you can use this variable in this code

  22. #47
    SitePoint Wizard
    Join Date
    Dec 2005
    Posts
    1,675
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok Shrapnel, getting a bit confusing now

    So are you saying to use the old method and scrap oddz code?

    something like:
    Code PHP:
    $sql5 =("SELECT category_id, venue_id FROM tbl_venues ORDER BY category_id", ARRAY_A); 
    			$result5 = mysql_query($sql5) or die(mysql_error());
    			$DATA5=array();
    			while ($arrVenues = mysql_fetch_array($result5, MYSQL_ASSOC)) {
    then use the output above ???
    The more you learn.... the more you learn there is more to learn.

  23. #48
    Non-Member
    Join Date
    Oct 2009
    Posts
    1,852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not exactly.
    Write $arrVenues instead of $DATA5 here
    and then fill it with data, as you do in the other scripts

  24. #49
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    4 Thread(s)
    This is the good standard way of doing the above code:

    Code php:
    $data = array();
    $sql = 'SELECT category_id, venue_id FROM tbl_venues ORDER BY category_id';
    $result = mysql_query($sql) or die(mysql_error());
    while ($row = mysql_fetch_assoc($result)) {
        array_push($data, $row);
    }
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  25. #50
    SitePoint Wizard
    Join Date
    Dec 2005
    Posts
    1,675
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it works, I was Expecting some errors, just a couple of tweaks

    Ok guys the full code

    select
    Code PHP:
    $sql5 = "SELECT category_id, venue_id FROM tbl_venues ORDER BY category_id"; 
    			$result5 = mysql_query($sql5) or die(mysql_error());
    			$arrVenues =array();
    			while ($row5 = mysql_fetch_array($result5, MYSQL_ASSOC)) {
    			$arrVenues[]=$row5;
    			}
    			$num_rows5=mysql_num_rows($result5);

    output
    Code PHP:
    <!-- list venue categories -->
    		<? 
    		$intCategory = null;
    		foreach($arrVenues as $arrVenue) {
     
    		if($intCategory != $arrVenue['category_id']) {
    			if($intCategory !== null) echo '</ul></div>';
    			echo '<div><h2>',$arrVenue['category_id'],'</h2><ul>';
    			$intCategory = $arrVenue['category_id'];
    		}
     
    			echo '<li>',$arrVenue['venue_id'],'</li>';
    		}
    		?>

    Thanks pmw57. If your way is more of a standard then I'll have to change a few things, 5 SELECT query's to be exact, but I'd like to get my code as good as it can be, what are the benefits of doing it your way?

    Thanks again Shrapnel . Just wondering can we change this output so it keeps inline with the others, without the echo's?
    The more you learn.... the more you learn there is more to learn.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •