www.webdeveloper.com
Results 1 to 6 of 6

Thread: [RESOLVED] Passing Variables

  1. #1
    Join Date
    Nov 2010
    Posts
    78

    resolved [RESOLVED] Passing Variables

    I'm trying to figure out with jquery how I can pass a variable. The variable I'm wanting to pass is the id of of the menu that way when it goes to view the menu items it'll only show the items associated to that menu. I thought I was right with what I have but it's now now loading anything.

    Code:
    <?php
        // Include the database page
        include ('../inc/dbconfig.php');
        
        // Number of records to show per page
        $display = 10;
        
        if (isset($_GET['p']) && is_numeric($_GET['p'])) {
            $pages = $_GET['p'];
        } else { // Need to determine
            
            // Count the number of records
            $q = "SELECT COUNT(id) FROM menustructures";
            $r = mysqli_query ($dbc, $q);
            $row = mysqli_fetch_array($r, MYSQLI_NUM);
            $records = $row[0];
            
            // Calculate the number of pages...
            if ($records > $display) { // More than 1 page.
                $pages = ceil($records/$display);
            } else {
                $pages = 1;
            }
        } // End of p IF.
        
        // Determine where in the database to start returning results...
        if (isset($_GET['s']) && is_numeric($_GET['s'])) {
            $start = $_GET['s'];
        } else {
            $start = 0;
        } // End of s IF.
        
        $query = "SELECT CONCAT_WS(' ', firstname, lastname) AS name, DATE_FORMAT(menustructures.datecreated, '%M %d, %Y') AS datecreated, menustructures.id, menuname FROM menustructures, handlers WHERE handlers.id = menustructures.creator_id LIMIT $start, $display";
        $result = mysqli_query ( $dbc, $query ); // Run The Query
        $rows = mysqli_num_rows($result);
    
    ?>
    <script>
       $(document).ready(function() {
            $('a', $('div#addform')).click(function() {
                $('#innerContent').load('forms/' + $(this).attr('id') + '.php');
            });
            $('a', $('td')).click(function() {
                $('#content').load('mods/' + $(this).attr('id') + '.php?id='$(this).attr('id'));
            });
            });
            
        });
    </script>
    <!-- Title -->
    			<div id="title" class="b2">
    				<h2>Menu Structures</h2>
    				<!-- TitleActions -->
    				<div id="titleActions">
    					<!-- ListSearch -->
    					<div class="listSearch actionBlock">
    						<div class="search">
    							<label for="search">Recherche</label>
    							<input type="text" name="search" id="search" class="text" />
    						</div>
    						<div class="submit">
    							<button type="submit" id="search-button" class="button"><strong><img src="img/icons/search_48.png" alt="comments" class="icon "/></strong></button>
    						</div>
    					</div>
    					<!-- /ListSearch -->
    					<!-- newPost -->
    						<div id="addform" class="newPost actionBlock">
    							<a href="#" id="addmenustructure" class="button"><strong>Add New Menu<img src="img/icons/add_48.png" alt="new post" class="icon "/></strong></a>
    						</div>
    					<!-- /newPost -->
    				</div>
    				<!-- /TitleActions -->
    			</div>
    			<!-- Title -->
    
                <!-- Inner Content -->
    			<div id="innerContent">
    
    				<!-- ListHeader -->
    				<div id="listHeader">
    					<p class="listInfos">
    						You have <?php if($rows == 0){echo '0';}else{echo $rows;} ?> menu structures.  
    					</p>
    					<div class="listActions">
    						<form action="" method="post">
    							<label for="actionSelect">With selected items: </label>
    							<select class="select" name="actionSelect" id="actionSelect">
    								<option>Edit</option>
    								<option>Delete</option>
    							</select>
    							<button class="button small-button"><strong>Apply</strong></button>
    						</form>
    					</div>
    				</div>
    				<!-- /ListHeader -->
                    <?php
                        if ($rows > 0) {
                    ?>
    				<!-- ListTable -->
    				<table cellspacing="0" class="listTable" id="postList">
    					<!-- Thead -->
    					<thead>
    						<tr>
    							<th class="first"><div></div></th>
    							<th><a href="#" title="Menu Structure Name">Menu Structure Name</a></th>
                                <th><a href="#" title="Menu Structure Items"></a></th>
    							<th><a href="#" title="Creator">Creator</a></th>
    							<th class="last"><a href="#" title="Date Created">Date Created</a></th>
    						</tr>
    					</thead>
    					<!-- /Thead -->
    					<!-- Tfoot -->
    					<tfoot>
    						<tr>
    							<td colspan="5">
    								<div class="inner">
    									<div class="paginate">
    										<?php 
                                            
                                                if ($pages > 1) {
                                                    
                                                    // Determine what page the script is on:
                                                    $current_page = ($start/$display) + 1;
                                                    
                                                    // If its not the first page, make a Previous button
                                                    if ($current_page != 1) {
                                                        echo '<span class="prev disabled"><a href="templates.php?s=' . ($start - $display) . '$p=' . $pages . '">&lt;&lt;</a></span>';
                                                    } 
                                                    
                                                    // Make all the numbered pages:
                                                    for ($i = 1; $i <= $pages; $i++) {
                                                        if ($i != $current_page) {
                                                            echo '<span class="current roundedBordersLite"><a href="templates.php?s=' . (($display * ($i - 1))). '$p=' . $pages . '">' . $i . '</a></span>';
                                                        } else {
                                                            echo $i . ' ';
                                                        }
                                                    } // End of FOR Loop.
                                                    
                                                    // If its not the last page, make a Next button:
                                                    if ($current_page != $pages) {
                                                        echo '<span class="next"><a href="#">&gt;&gt;</a></span>';
                                                    }
                                                } // End of links pages.
                                            
                                            ?>
    									</div>
    								</div>
    							</td>
    						</tr>
    					</tfoot>
    					<!-- /Tfoot -->
    					<!-- Tbody -->
    					<tbody>
    						<?php 
    				        while ( $row = mysqli_fetch_array ( $result, MYSQL_ASSOC ) ) {
                              echo '
                              <tr>
                              <td><input type=checkbox class=checkbox /></td>
    						  <td>' . $row['menuname'] . '</a></td>
                              <td><a href=# id="' . $row['id'] . '" title="' . $row['menuname'] . ' Structure Items">Menu Items</a></td>
    						  <td>' . $row['name'] . '</a></td>
    						  <td class=last>' . $row['datecreated'] . '</td>
    						  </tr>';
                            }
                        ?>
    					</tbody>
    					<!-- /Tbody -->
    				</table>
                    <?php
                            }
                        ?>
    				<!-- /ListTable -->
    
    			</div>
    			<!-- /Inner Content -->

  2. #2
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    multiple selector
    Code:
    // not
    $('a', $('div#addform')).click(function() {
    // like this
    $('a, div#addform').click(function() {
    Code:
       $(document).ready(function() {
            $('a', $('div#addform')).click(function() {
                $('#innerContent').load('forms/' + $(this).attr('id') + '.php');
            });
            $('a', $('td')).click(function() {
                $('#content').load('mods/' + $(this).attr('id') + '.php?id='$(this).attr('id'));
            });
            }); // remove
            
        });
    The 1st and 2nd multiple selector groups both contain the anchor. Only the 2nd load would be applied.
    At least 98% of internet users' DNA is identical to that of chimpanzees

  3. #3
    Join Date
    Nov 2010
    Posts
    78
    That did not work.

  4. #4
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Are the paths to the documents correct?
    Have you tested the jQuery to see if it creates events for the selectors?
    At least 98% of internet users' DNA is identical to that of chimpanzees

  5. #5
    Join Date
    Nov 2010
    Posts
    78
    I'm not sure how to do that. I have firebug but I only know how to use the plugin for html,css purposes only.

  6. #6
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    A simple alert would give an indication
    Code:
       $(document).ready(function() {
            $('a, div#addform').click(function() {
                alert($(this).attr('id') ); //$('#innerContent').load('forms/' + $(this).attr('id') + '.php');
            });
        });
    At least 98% of internet users' DNA is identical to that of chimpanzees

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles