Jump to content

yanks6rule

New Members
  • Posts

    6
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

yanks6rule's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. So I was able to print an array of arrays after working through some steps. I was wondering if anyone could help me loop through this data to output the data I am looking for. Here is my code that creates the multidimensional array: while($row = mysql_fetch_array($sql)) { $plot[] = array('x' => $row[1], 'y' => $row[2]); } and the output is this: Array ( [0] => Array ( [x] => 160 [y] => 61 ) [1] => Array ( [x] => 91 [y] => 145 ) [2] => Array ( [x] => 83 [y] => 151 ) ) I was wondering how I can loop through this data to get $plot[0] = (160, 61) I was trying foreach statements but not seemed to work. Thanks, Yanks
  2. Hey everyone, I have just started getting back into PHP programming and I have hit a snag. I am trying to create an array of X,Y data, but I am not sure this is possible. I have two fields in my MySQL db that are named x_coor and y_coor. I want to loop through my db and pull these out as X,Y data and have the output be in an array or something similar that will give me this: $plot[0] = (x_coor(row1), y_coor(row1)); $plot[1] = (x_coor(row2), y_coor(row2)); and so on and so forth. Is this possible or do I need to come up with a better way to do this.
  3. I have a table that is populated from a MySQL database. The first column of this table is a checkbox that has the value remove[$guestID]. I am giving the user the opportunity to remove a guest they are no longer bringing or have to edit. If you have 3 guests with the following guestIDs 3, 6, 15 and you wanted to remove guest 15 you could check the last checkbox and I would want to check to see if any of the three checkboxes are marked and if they are I would remove the guest by matching the guestID to the value in the checkbox. Does this make sense or am I over thinking a simple problem. I can supply code that I have, I think I have to put this into an array but not sure how to check for the value being checked or not checked.
  4. [!--quoteo(post=373577:date=May 13 2006, 04:11 PM:name=Crayon Violent)--][div class=\'quotetop\']QUOTE(Crayon Violent @ May 13 2006, 04:11 PM) [snapback]373577[/snapback][/div][div class=\'quotemain\'][!--quotec--] well it's kind of hard to know how to fix your problem without you showing code. but offhand i'd say check your frames if you have them, make sure they are being updated in the right place. if it's not that, then check your loops and conditions to see if you aren't inadvertantly double iterating the table, or maybe there are 2 conditions that turn out to be true when you want to only do one or the other in which you should have if/else not if/if failing all that, what do you mean, "include the page again?" do you mean to say that the last line of code involves doing an include of the [i]same[/i] script? that's probably your problem right there. if you want the page to reload after the user submits, in your form tag add <form method = 'post' [!--coloro:blue--][span style=\"color:blue\"][!--/coloro--]action='$PHP_SELF'[!--colorc--][/span][!--/colorc--]> and ditch that include. [/quote] I can include my code if you would like it just is rather lengthy that is why I tried to pair it down so that I could explain it best. I have kind of fixed my problem, but I know it is not the right way of doing it. I am going to include some of my code here to see if it will help, if you want more let me know. I am calling a page called guest_reg.php, which is displayed below: <?php include "start_session.php"; //Start Coding $event = $_SESSION['event']; $pid = $_SESSION['pid']; echo "<p><font size=+3>$event</font></p>"; include "mysql_connect_snacks.php"; mysql_select_db("chemdocs"); $guest_qry = "SELECT * FROM guest WHERE pid='$pid'"; $guest_res = mysql_query($guest_qry) or exit(mysql_error()); $num = mysql_num_rows($guest_res); if ($num != 0) { $guest_table = ' <table width =\"50%\"> <tr><th colspan=5><div align="center">Guests That Have Been Added</div></th></tr> <tr><th>Check</th><th>Last Name</th><th>First Name</th><th>M.I.</th><th>Relation</th></tr>'; $i = 0; while (($i < $num) && ($row = mysql_fetch_array($guest_res))) { $guest_table .= ' <tr> <td width=5%><input type="checkbox" name="update['. $row['gid'] .']" value="1" /></td> <td><div align="center"><span class="black_text">' . $row['glastname'] . '</span></div></td> <td><div align="center"><span class="black_text">' . $row['gfirstname'] . '</span></div></td> <td><div align="center"><span class="black_text">' . $row['mi'] . '</span></div></td> <td><div align="center"><span class="black_text">' . $row['relation'] . '</span></div></td> </tr>'; $i++; } $guest_table .= '</table>'; echo "$guest_table"; } else { echo "No guests are yet registered"; } include "forms.php"; ?> Forms.php is just a form with first, last, MI and relation and then I do some error check and here is the last bit, that I did a quick fix on by using an HTML refresh function. If you can let me know if there is a better way to make the page show up with a table with all guests of a member shown and then the form to add another guest and everytime they hit add guest a guest will be added to the table let me know. //Select DB: mysql_select_db("chemdocs"); //Set MI variable $mi = $_POST[mi]; $pid = $_SESSION['pid']; //Insert Statement $query = "INSERT INTO guest SET glastname = '" . mysql_real_escape_string($glastname) . "', gfirstname = '" . mysql_real_escape_string($gfirstname) . "', mi = '" . mysql_real_escape_string($mi) . "', relation = '" . mysql_real_escape_string($relation) . "', pid = '". mysql_real_escape_string($pid) ."'"; $result = mysql_query($query) or die(mysql_error()); echo "guest added successfully"; unset($_POST); function Refresh_Page($page) { $refresh='<html><META HTTP-EQUIV="Refresh" CONTENT="0; URL='.$page.'"></html>'; echo $refresh; } Refresh_Page('http://snacks.chem.umass.edu/session/guest_reg.php'); } } THanks
  5. I have this page where a member is allowed to add guests to an event they are attending. The way the page is setup is as follows: -Check for Session to make sure member is logged in -Query guest table, to check for any guests that have been entered by this member -If guest exists put them in a table for display -else say no registered guests -Show a form that allows for a new guest to be inserted -insert new guest into guest table -unset($_POST) -then include the page again The last part is to reload the table on top to show all guests that have been added where they can remove or edit. The problem I am having is that when I hit submit the new page is loaded underneath the table from the original page. Meaning if I have a guest already added when I add a second guest, A table with the first guest stays and then underneath that a new table comes up with both guests and then the form. Is there a way around this, I can't use headers because I have already started output and I don't want to use output buffering if I don't have to because I heard there is a lot of security issues if not used properly and I don't have enough experience to make sure I am not buffering without sending sensitive information. If you can help, great. Thanks Yanks
  6. I have conquered the langauge to take the information from one MySQL table and display it with PHP in a web broswer. I am not trying to do take information from two tables and display it. Maybe someone will be able to point me to a good tutorial to do this, but I am having problems coming up with a good flow to this problem. I have alumni sign in to a web page. On their welcome page they can update their information. I have made it so that the login and logout work fine. I now want to add a way for them to register for an event. The way I had in mind is what follows, not all of this is under my control because I am not allowed to create my own tables since the head IT guy wants control but he doesn't want to do any of the PHP scripting to make any of this work. I have the following tables 1. Alumni 2. Event 3. Alumni_event 4. guest When registering I want the first page to be for the person to select an event, then hit submit. The next page will show which event they selected and ask them to insert their first guest. Then the have the option to review and finish or add another guest. If they hit add another guest they guest they just added will appear with a radio button and the option to delete and the form will be blank to add guest 2. I am having a problem trying to display the event after hitting submit because I can't figure out exactly how to store the data from two tables in variables so that I can output it in text. My SQL query is: $query = "SELECT alumni_event.eid, event.eid, event.event WHERE alumni_event.eid='$eid' AND event.eid=alumni_event.eid"; and then I just tried a mysql_num_rows() and a while loop using mysql_result() to store the data, but I didn't think it would work because it seems like you won't have one a specific row because you are over multiple columns, but it looked like this: $result = mysql_query($query); $num = mysql_num_rows($result); $i = 0; while ($i < $num) { $eventID = mysql_result($result,$i,"eid"); $alumnusID = mysql_result($result,$i,"pid"); $event_name = mysql_result($result,$i,"event"); } Sorry this is so long but if anyone can point me in the right direction that would be great. Thanks, Yanks
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.