简体   繁体   中英

jQTouch and dynamic php/mysql list linking to inside anchor and pass on a php/mysql variable

I'm working on a full screen web app for the iPhone/iPod, using the latest jQTouch.

On the first "page" (as in ) a list is generated from a mysql database. Every item of that list should be a link to another "page" and pass on a variable that is unique to that item (so that the next "page" knows which item was clicked on). For now I have this:

<ul class="rounded plastic">
    <?php
        $data = mysql_query("SELECT * FROM tempCursist WHERE achternaam BETWEEN 'a%' AND 'e%' ORDER BY achternaam, voorletters");
        while ($row = mysql_fetch_assoc($data)) { ?>
            <li>
            <a href="#>
            <?php echo $row['achternaam'].", ".strtoupper($row['voorletters'])." ".$row['tussenvoegsel']." (".$row['voornaam'].")";?>
            </a>
            </li>
        <?php }; ?>
</ul>

As you can see the anchor tag is just "#", but the goal is to jump to a new "page" (using the jQTouch framework, as this is intended for an iPhone/iPod) and pass on something that is unique to the clicked on dynamically generated item, so that the next "page" knows what to work with.

By the way, the table does have a primary key ($row['id']), so maybe someone knows how to make use of that...?

Many thanks in advance!

jQtouch pages can all be loaded with a single HTTP GET and the information can be passed to the jQTouch page via jquery/javascript (the page itself hasn't refreshed, only the jQTouch page has changed).

Let's assume the id of one of your pages is 'info' and you retrieve that from your sql query.

<body>
<div id="about">
<ul class="rounded plastic">
        <?php 
            $data = mysql_query("SELECT * FROM tempCursist WHERE achternaam BETWEEN 'a%' AND 'e%' ORDER BY achternaam, voorletters");
            while ($row = mysql_fetch_assoc($data)) : ?>
            <li>
                <a href="#<?php echo $row['id']; // this will show the info 'page' aka div based on what we assumed above ?>">
                <?php echo $row['achternaam'].", ".strtoupper($row['voorletters'])." ".$row['tussenvoegsel']." (".$row['voornaam'].")";?>
                </a>
            </li>
            <?php endwhile; ?>
</ul>
</div>

<div id="info">
    <!-- This will be shown after the 'a' tag is clicked with id of info -->
</div>
</body>

Don't forget the # in the href. You can use jQuery to find whatever information you need on the jQTouch page that is shown now. The actual page hasn't refreshed.

Note: info should NOT be used as an id in your database.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM