Results 1 to 13 of 13

Thread: Table variable to new web page

  1. #1
    Join Date
    Oct 2014

    Table variable to new web page

    I have a table populated from a DB and the values within the table, when displayed are a hyperlink to a new page, which is the same page for everything. The point of the new page is change the value in the CLICKED cell. The goal is to change the value of the chosen cell to another predetermined value. I am unsure how to get the particular value from the CLICKED cell to the new page??

    Here is the code I have now:

    $result = mysqli_query($con,"SELECT * FROM volunteer");

    echo "<table class='std'>
    <th>HEAD FLAGGER</th>
    <th>CORNER FLAGGER 1</th>
    <th>CORNER FLAGGER 2</th>
    <th>CENTER SCORER 1</th>
    <th>CENTER SCORER 2</th>
    <th>BOARD 1</th>
    <th>BOARD 2</th>

    while($row = mysqli_fetch_array($result)) {
    echo "<tr>";
    $website = "localhost/vchange.php";
    $class = $row['class'];
    $head_flagger = $row['head_flagger'];
    $corner_one = $row['corner_one'];
    $corner_two = $row['corner_two'];
    $center_one = $row['center_one'];
    $center_two = $row['center_two'];
    $board_one = $row['board_one'];
    $board_two = $row['board_two'];
    $stager= $row['stager'];

    echo("\t\t<td>" . "$class" . "</td>\n");
    echo("\t\t<td>" . "<a href='http://$website' target = '_blank'>" . "$head_flagger" . "</a></td>\n");
    echo("\t\t<td>" . "<a href='http://$website' target = '_blank'>" . "$corner_one" . "</a></td>\n"); echo("\t\t<td>" . "<a href='http://$website' target = '_blank'>" . "$corner_two" . "</a></td>\n");
    echo("\t\t<td>" . "<a href='http://$website' target = '_blank'>" . "$center_one" . "</a></td>\n"); echo("\t\t<td>" . "<a href='http://$website' target = '_blank'>" . "$center_two" . "</a></td>\n");
    echo("\t\t<td>" . "<a href='http://$website' target = '_blank'>" . "$board_one" . "</a></td>\n");
    echo("\t\t<td>" . "<a href='http://$website' target = '_blank'>" . "$board_two" . "</a></td>\n");
    echo("\t\t<td>" . "<a href='http://$website' target = '_blank'>" . "$stager" . "</a></td>\n"); echo "</tr>";

    Initially to start, all the values are 'XX' and the user clicks the HREF and a new page (vchange.php) will open and change the 'XX' to a value already determined.

    I am not sure how to know the location of that chosen cell to the new webpage!!! STUCK!

    I would like to remain in PHP as that is what I am learning.


  2. #2
    Join Date
    Jul 2013
    Voorheesville NY USA
    Add a GET parm to your anchor tag which is unique for each anchor. Then in the called script just grab that GET parm and use it.
    PS - If you're posting here you should be using:

    ini_set('display_errors', '1');

    at the top of ALL php code while you develop it!

  3. #3
    Join Date
    Oct 2014
    Thanks, I have been playing with that, but I am stuck on how to GET the right table cell....can you give me a bit of the code to understand?

  4. #4
    Join Date
    Oct 2014
    Here is what I been working on, but I getting errors. Something is not right here...

    echo("\t\t<td>" . "<a href='http://$website?V_ID=$row['vol_job']' target = '_blank'>" . "$head_flagger" . "</a></td>\n");

  5. #5
    Join Date
    Jul 2013
    Voorheesville NY USA
    When that anchor triggers whatever script it is going to, you will have a $_GET['V_ID'] to give you some idea of exactly which cell was clicked. Unless $row['vol_job'] is not unique across the whole table. What are you trying to retrieve with this info - the exact row of the table clicked on? If so you should use the record key of the dat in that row.

    Why do you need an anchor tag in every cell of the rows? They look like they are all going to the same place so why repeat them?

    Plus - you have an extra tr tag being output for each row.
    PS - If you're posting here you should be using:

    ini_set('display_errors', '1');

    at the top of ALL php code while you develop it!

  6. #6
    Join Date
    Oct 2014
    Thanks, sorry for the delay getting back on this, been sick and working too much at my real job!

    V_ID is a row identifier.

    There is an Anchor Tag in each cell as the user picks which cell they want to change. The cells are populated with 'XX' to start and then are to change to there number as they choose them. each user will change up to 5 cells as they volunteer for different jobs.

    I will work on your suggestions, just stuck on how to move forward.


  7. #7
    1) Where's your SCOPE, THEAD and TBODY

    2) why are you using multiple echo to do one echo's job

    3) why are you using double-quotes and parsed tabs, just trying to make it harder to read?

    4) why are you wasting time making copies of values for nothing more than wasting memory?

    5) why are you doing string additions BETWEEN static strings?!?

    6) why are you wasting memory doing string additions on static echo elements?

    7) why are you redefining $website inside the loop when it's static?

    8) this is 2014 not 1997, you have no business having the 'target' attribute on a site, much less shoving new windows down the user's throat with it.

    9) doesn't make a lot of sense for them all to be getting the same anchor... If you want to pass a unique value to them, you need to pass a unique value. In this case I'd do it using $_GET -- something like

    <a href="', $website, '?row=', urlencode($row['V_ID'], '&amp;col=', urlencode($index), '&amp;value=', urlencode($row['head_flagger']), '">
    10) since those TD are all so much alike, I'd put them in a function.

    11) since you are only accessing them associative, use fetch_assoc not fetch_array (or pass the assoc restriction to it)

    So, let's drag that kicking and screaming into the light:

    $website = 'http://localhost/vchange.php';
    echo '
    	<table class="std">
    				<th scope="col">CLASS</th>
    				<th scope="col">HEAD FLAGGER</th>
    				<th scope="col">CORNER FLAGGER 1</th>
    				<th scope="col">CORNER FLAGGER 2</th>
    				<th scope="col">CENTER SCORER 1</th>
    				<th scope="col">CENTER SCORER 2</th>
    				<th scope="col">BOARD 1</th>
    				<th scope="col">BOARD 2</th>
    				<th scope="col">STAGER</th>
    function tdAnchor($index) {
    	global $row, $website;
    	echo '
    					<a href="', $website, '?row=', urlencode($row['V_ID'], '&amp;col=', urlencode($index), '&amp;value=', urlencode($row['head_flagger']), '">
    						', $row['head_flagger'], '
    $stmt = $con->query('SELECT * FROM volunteer');
    while ($row = $stmt->fetch_assoc()) {
    	echo '
    				<td>', $row['class'], '</td>';
    	echo '
    echo '
    On your next page (vchange.php) $_GET['row'] == the $row['v_id'] they clicked on, $_GET['col'] is the name of the column / result index they clicked on, and $_GET['value'] would be the value of that cell.

    Hope this helps.
    Last edited by deathshadow; 10-31-2014 at 01:11 PM. Reason: missed $website as a global in function.

  8. #8
    Join Date
    Oct 2014
    Ok deathshadow, a little to absorb and I am going thru now to understand all that you are telling me - thanks!

    I copied it and am trying to use it, so I can better understand it, but there an error of an unexpected ';' at the end of the function that I am attempting to figure out now.

    Thanks for the lesson!

  9. #9
    Quote Originally Posted by Bigmo View Post
    I copied it and am trying to use it, so I can better understand it, but there an error of an unexpected ';' at the end of the function that I am attempting to figure out now.
    I missed a ) on one of the urlencode, what I get for typing it in the edit box here instead of a real editor.

    echo '
    					<a href="', $website, 
    					'?row=', urlencode($row['V_ID']),
    					'&amp;col=', urlencode($index), 
    					'&amp;value=', urlencode($row['head_flagger']), '">
    					', $row['head_flagger'], '
    Should do the trick. Sometimes splitting stuff into multiple lines like that makes it easier to find the error.

  10. #10
    Join Date
    Oct 2014
    Ok deathshadow, I am learning something here, my inexperience is making it slow...but thank you.

    I found the error too and they only issue I am having at this moment is that your code from the function is only using the data from 'head_flagger' and not the data from the other columns in the DB such as stager or any of the others you refer to in the function that are part of the DB.

    I see that value=urlencode($row['head_flagger' grabs the value of that field, though only in 'head_flagger'. and the data for all the columns is the data from 'head_flagger' only...

    So while I am understanding what you have done, I am not sure how to fix for each column. Separate functions is a lot of wasted time that you scolded me for before...

    Please point me a direction (hoping I made myself clear and what I need).

    Thanks for the teaching, I realize I have a long way to go!

  11. #11
    oops, that's another typo.

    echo '
    					<a href="', $website, '?row=', urlencode($row['V_ID'], '&amp;col=', urlencode($index), '&amp;value=', urlencode($row[$index]), '">
    						', $row[$index], '
    Though I'm not sure you even need to pass 'value' -- server side you should be probably using the database to pull the row again instead of sending the data back and forth to/from the server. Usually the less data you pass back and forth between the two the better. If you can get by with passing what row was clicked and what column was clicked, that should be all the info you need on the server.

    Really though this is treading into being so huge I wouldn't be doing this in the first place -- to what end is this being done? I think a lot of the mistakes I'm making trying to understand what you want comes from my having no clue what the data actually is and what you are trying to do with it.

  12. #12
    Join Date
    Oct 2014
    Thanks, I was real close, only reason I did not have that fix is I did not remove a set of ' '! IT works

    My goal here is to allow users to select a volunteer duty that is prefilled with 'XXX' then their registered number replaces the 'XXX' and we know they signed up for that duty. basically my thoughts were to have them click the 'XXX' in the row and column they want, the code checks to be sure that spot is still available, and changes it to their number. boom we know what they signed up for!

    I later had a thought that going to a another webpage is a waste, and the number could just toggle when they selected, so long as it is still available, and not open a new page, just refresh the current one. If they made a mistake they could click again and it toggles back to 'XXX'., but I have not put thought into how to accomplish that yet. They need to sign for 5 duties.

    Make sense?

  13. #13
    Ok, I get it. I would FIRST make it work as a normal sub web-page load, THEN enhance it with AJAX.

    All good JavaScript should enhance and already working page, instead of being "the only way it works" -- doing so is actually pretty easy and can speed development since you can get client-side and server-side working secure and flawless with just markup and PHP FIRST; then just have a little bit of PHP that does the same thing sending less data and scripting that just intercepts the anchor and plugs in the data.

    I'd put an ID on the TBODY, getElementsByTagName('a') on it to get all those nested anchors, detect if the anchor is calling "$website" and if so add onclick to it, AJAX the response to a different URI and cancel event bubbling.

    Don't know how familiar you are with JS and AJAX though.

    In any case, IF you want to go AJAX (which for updating just one field of many is a sane choice) ALWAYS try to make it work without AJAX FIRST, then enhance it. If nothing else it keeps the implementation logic simpler and lets you build in stages.

    Keeping the logic simple for the approval you could even just have the AJAX version of the update handler simply return true/false if the user gets that slot. (or even better, 0 or the user's name/id)

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.15539 seconds
  • Memory Usage 2,992KB
  • Queries Executed 15 (?)
More Information
Template Usage (34):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (4)bbcode_code
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (13)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (13)postbit
  • (13)postbit_onlinestatus
  • (13)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (71):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates