Jump to content

aaronrb

Members
  • Posts

    31
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

aaronrb's Achievements

Newbie

Newbie (1/5)

1

Reputation

  1. Thanks for the help, somehow by including an ORDER BY it seems to work nicely now !!
  2. OK, i have been looking through the code i have... <?php session_start(); // NEVER forget this! if(!isset($_SESSION['loggedin'])) { // Get the full URL of the current page $return = $_SERVER['REQUEST_URI']; // header('Location:http://www.fsma.co.uk/?refer='.rawurlencode($return)); die("To access this page, you need to <a href='login.php?return=".$return."'>LOGIN</a>"); // Make sure they are logged in! } // What the !isset() code does, is check to see if the variable $_SESSION['loggedin'] is there, and if it isn't it kills the script telling the user to log in! ?><?php ini_set('display_errors',1); error_reporting(E_ALL); ?> <!DOCTYPE html> <html> <head><link rel="stylesheet" type="text/css" href="style.css"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title></title> </head> <body><div class="return_to_main"><a href="index.php"><img src="images/main_page.jpg" /></a></div> <center><h1> View Accounts </h1><br /><?php //connect to DB //$conn = mysql_connect('localhost', 'web77-fsma', 'raymond'); //mysql_select_db("web77-fsma", $conn) or die(mysql_error()); $mysqli = new mysqli('localhost', 'web77-fsma', 'raymond', "web77-fsma"); //$sql = mysql_query("SELECT * FROM accounts GROUP BY agreement_id ORDER BY payer_name"); if ($mysqli->connect_errno) { echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error; } $sql = "SELECT * FROM accounts INNER JOIN students ON accounts.agreement_id = students.agreement_id"; //if( $sql->num_rows === 0){ die("No Accounts Available");} //$row_cnt = $result->num_rows; if ($stmt = $mysqli->prepare($sql)) { /* execute query */ $stmt->execute(); /* store result */ $stmt->store_result(); if($stmt->num_rows === 0){ die('No Accounts Available');} printf("<b>Totl Accounts: </b> %d", $stmt->num_rows); /* close statement */ $stmt->close(); } ; ?> <table > <tbody> <tr class="header"> <td><b>Payers Name</b></td> <td><b>No. of Students</b></td> <td><b>Account I.D.</b></td> <td><b>Contract Length</b></td> <td><b>Date Started</b></td> <td><b>Fee</b></td> </tr> <?php $res = $mysqli->query($sql); //We are starting with no states listed yet. $last_account = NULL; while ($row = $res->fetch_assoc()){ //Check if the last state listed is not the same as the current one. //If it is not the same, echo the new state name. if($last_account != $row['agreement_id']){ // while($row = mysql_fetch_array($sql)){ ?> <tr > <td><center><b> <?php echo $row['payer_name']; ?> </b></center></td> <td><center><b><?php echo mysqli_num_rows($res); ?></b></center></td> <td><b><?php echo $row['agreement_id']; ?></b></td> <td><center><b><?php echo $row['contract_length']; ?> </b></center></td> <td><center><b><?php echo $row['contract_start']; ?></b></center></td> <td><center><b>£<?php echo $row['payment_amount']; ?></b></center></td> </tr> <tr> <?php //Assign the new state as the last state. $last_account = $row['agreement_id']; } ?> <td><?php echo $row['name']; ?></td> <?php } ?> </tr> </table></center> </body> </html> And it appears i have 1 account number which is display ALL 3 students underneath... but then the rest only show 1 or 2 of the linked students! All details are in DB are correct, im confused how it can work for one result and not the rest !
  3. Ah i see what you mean, thanks... sorry i must sound really stupid, now i have another issue. Shown in the image below, i have highlighted the same account, which has 3 students linked to it, but shows 2 of them together and the 3 on its own.. In accounts table, there is only one account with this number "20134652" and then in the students table, there are 3 students with the same account number "20134652"
  4. Ok, i have found out for some reason the JQUERY SCRIPT i added to show a little pop up of student names, on mouseover.. was doing something to prevent it from working.. as i followed jessica's tutorial which worked fine.. then i added the JQUERY to there and it no longer worked... so to get this page working ASAP i have removed the jquery and just added a row to the table... (and changed to the mysqli code..) <table > <tbody> <tr class="header"> <td><b>Payers Name</b></td> <td><b>No. of Students</b></td> <td><b>Account I.D.</b></td> <td><b>Contract Length</b></td> <td><b>Date Started</b></td> <td><b>Fee</b></td> </tr> <?php $res = $mysqli->query($sql); //We are starting with no states listed yet. $last_account = NULL; while ($row = $res->fetch_assoc()){ //Check if the last state listed is not the same as the current one. //If it is not the same, echo the new state name. if($last_account != $row['agreement_id']){ // while($row = mysql_fetch_array($sql)){ ?> <tr > <td><center><b> <?php echo $row['payer_name']; ?> </b></center></td> <td><center><b><?php echo mysqli_num_rows($res); ?></b></center></td> <td><b><?php echo $row['agreement_id']; ?></b></td> <td><center><b><?php echo $row['contract_length']; ?> </b></center></td> <td><center><b><?php echo $row['contract_start']; ?></b></center></td> <td><center><b>£<?php echo $row['payment_amount']; ?></b></center></td> </tr><tr><td><?php echo $row['name']; ?></td></tr> <?php //Assign the new state as the last state. $last_account = $row['agreement_id']; } //echo "{$row['city']}<br />"; } ?> </table> but the only issue now is that for the $row['name'] some accounts have more than one student, how can i get it to list all the students for that account on that row... ?? I have attached an image of hte output, the red circles show the student names, which for some rows should have multiple names
  5. oops sorry thats because i had a group on the payer_name.. so it does show correctly in phpmyadmin
  6. its the $row['name'] that doesnt show correctly. here: <div id="pop-up"> <h3>Students Linked to this Account:</h3> <p> <?php echo $row['name']; ?> </p> </div> i have just checked using PHPMYADMIN, using the same query, it shows students and payers names correctly... however same payers have 2 or 3 students linked to them, and it only shows one..
  7. <center><h1> View Accounts </h1><br /><?php //connect to DB $conn = mysql_connect('localhost', 'web77-fsma', 'raymond'); mysql_select_db("web77-fsma", $conn) or die(mysql_error()); //$sql = mysql_query("SELECT * FROM accounts GROUP BY agreement_id ORDER BY payer_name"); $sql = mysql_query("SELECT * FROM accounts INNER JOIN students ON accounts.agreement_id=students.agreement_id GROUP BY accounts.payer_name"); //if(mysql_num_rows($sql) === 0){ die("No Accounts Available");} //echo '<b>Total Accounts: </b>'.mysql_num_rows($sql); ?> <table > <tbody> <tr class="header"> <td><b>Payers Name</b></td> <td><b>No. of Students</b></td> <td><b>Account I.D.</b></td> <td><b>Contract Length</b></td> <td><b>Date Started</b></td> <td><b>Fee</b></td> </tr> <?php while($row = mysql_fetch_array($sql)){ ?> <tr > <td><center><b> <div id="container"> <a href="#" id="trigger"><?php echo $row['payer_name']; ?> </a> <!-- HIDDEN / POP-UP DIV --> <div id="pop-up"> <h3>Students Linked to this Account:</h3> <p> <?php echo $row['name']; ?> </p> </div> </div> </b></center></td> <td><center><b><?php echo mysql_num_rows($sql); ?></b></center></td> <td><b><?php echo $row['agreement_id']; ?></b></td> <td><center><b><?php echo $row['contract_length']; ?> </b></center></td> <td><center><b><?php echo $row['contract_start']; ?></b></center></td> <td><center><b>£<?php echo $row['payment_amount']; ?></b></center></td> </tr> <?php } ?> </table></center>
  8. Sorry i didnt see you had replied before i did.. im going to look at the tutorial now...
  9. Ok, i have this query SELECT * FROM accounts INNER JOIN students ON accounts.agreement_id=students.agreement_id it displays a student name in the box, but still its the same name for every row.
  10. I have rewritten things a couple of times to make sure the variables were in the right place.. and i did look at join, but got rather confused.. Il have another look now.. Thanks for you reply !
  11. Hi everyone.. i have 2 tables... Accounts & Students.. Both contain the field agreement_id which is used to link the 2. I am using this query to display a table of results $sql = mysql_query("SELECT * FROM accounts GROUP BY agreement_id ORDER BY payer_name"); if(mysql_num_rows($sql) === 0){ die("No Accounts Available");} echo '<b>Total Accounts: </b>'.mysql_num_rows($sql); ?> <table > <tbody> <tr class="header"> <td><b>Payers Name</b></td> <td><b>No. of Students</b></td> <td><b>Account I.D.</b></td> <td><b>Contract Length</b></td> <td><b>Date Started</b></td> <td><b>Fee</b></td> </tr> <?php while($row = mysql_fetch_array($sql)){ ?> ALL results display fine from this query... and then there is a CSS popbox on mouse over the payers name.. and the box displays the students name which is retrieved from the students DB. But for EVERY result in the first query, the students name in the popbox is the same... Here is my complete code. Its this area that seems to be the problem <!-- HIDDEN / POP-UP DIV --> <div id="pop-up"> <h3>Students Linked to this Account:</h3> <p><?php $id = $row['agreement_id']; $sql2 = mysql_query("SELECT * from students WHERE agreement_id = '$id' "); while($row2 = mysql_fetch_array($sql2)){ echo $row2['name']; } ?> <?php session_start(); // NEVER forget this! if(!isset($_SESSION['loggedin'])) { // Get the full URL of the current page $return = $_SERVER['REQUEST_URI']; // header('Location:http://www.fsma.co.uk/?refer='.rawurlencode($return)); die("To access this page, you need to <a href='login.php?return=".$return."'>LOGIN</a>"); // Make sure they are logged in! } // What the !isset() code does, is check to see if the variable $_SESSION['loggedin'] is there, and if it isn't it kills the script telling the user to log in! ?><?php ini_set('display_errors',1); error_reporting(E_ALL); ?> <!DOCTYPE html> <html> <head><script type="text/javascript"> window.onload = function(){ var text_input = document.getElementById ('id'); text_input.focus (); text_input.select (); } </script><link rel="stylesheet" type="text/css" href="style.css"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title></title> <style type="text/css"> h1, h3 { margin: 0; padding: 0; font-weight: normal; } div#container { } /* HOVER STYLES */ div#pop-up { display: none; position: absolute; width: 280px; padding: 10px; background-color: #ffffff; border: 1px solid #000000; font-size: 90%; } </style> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js"></script> <script type="text/javascript"> $(function() { var moveLeft = 20; var moveDown = 10; $('a#trigger').hover(function(e) { $('div#pop-up').show(); //.css('top', e.pageY + moveDown) //.css('left', e.pageX + moveLeft) //.appendTo('body'); }, function() { $('div#pop-up').hide(); }); $('a#trigger').mousemove(function(e) { $("div#pop-up").css('top', e.pageY + moveDown).css('left', e.pageX + moveLeft); }); }); </script> </head> <body><div class="return_to_main"><a href="index.php"><img src="images/main_page.jpg" /></a></div> <center><h1> View Accounts </h1><br /><?php //connect to DB $conn = mysql_connect('localhost', 'web77-fsma', 'raymond'); mysql_select_db() ***** date removed ****** $sql = mysql_query("SELECT * FROM accounts GROUP BY agreement_id ORDER BY payer_name"); if(mysql_num_rows($sql) === 0){ die("No Accounts Available");} echo '<b>Total Accounts: </b>'.mysql_num_rows($sql); ?> <table > <tbody> <tr class="header"> <td><b>Payers Name</b></td> <td><b>No. of Students</b></td> <td><b>Account I.D.</b></td> <td><b>Contract Length</b></td> <td><b>Date Started</b></td> <td><b>Fee</b></td> </tr> <?php while($row = mysql_fetch_array($sql)){ ?> <tr > <td><center><b> <div id="container"> <a href="#" id="trigger"><?php echo $row['payer_name']; ?> </a> <!-- HIDDEN / POP-UP DIV --> <div id="pop-up"> <h3>Students Linked to this Account:</h3> <p><?php $id = $row['agreement_id']; $sql2 = mysql_query("SELECT * from students WHERE agreement_id = '$id' "); while($row2 = mysql_fetch_array($sql2)){ echo $row2['name']; } ?> </p> </div> </div> </b></center></td> <td><center><b><?php echo mysql_num_rows($sql2); ?></b></center></td> <td><b><?php echo $row['agreement_id']; ?></b></td> <td><center><b><?php echo $row['contract_length']; ?> </b></center></td> <td><center><b><?php echo $row['contract_start']; ?></b></center></td> <td><center><b>£<?php echo $row['payment_amount']; ?></b></center></td> </tr> <?php } ?> </table></center> </body> </html> Any help is much appreciated, have been racking my brains for 2 days !!!! ARGH! Thanks,
  12. Nice One, Guys thanks for the help. Regards A 8-)
  13. hey aeafisme23, ya know thats not exactly what i was after, but its great and does the job. tHANK you so much.... just one small query, how would i be able to do something similiar to this, Student 1's details | Student 2's Details ------------------------------------------------------- Student 3's Details | Student 4's Details if you can imagine that as a table.. Thanks again...
  14. i had a similar problem, and i searched many mail servers, in the end i found desknow, works great and works with a web interface. how ever i am unsure is it work with xammp i got rid of that along time ago !
  15. Hi Guys, been a while since coding in php, i am trying to pull information out of a database, and loop it in a table so it displays a new set of information per cell. there will be 2 or 3 cells per row and as many rows as need. i have the information coming out of the db OK. when it puts it into two rows, it shows the same data, i know i have put the </tr> in the wrong place, but i cant work out where to put it. <body> <table width="95%" border="1"> <? require 'db_connect.php'; $query = "SELECT * FROM tkd_members where status = 'Active' ORDER BY lastname ASC"; $result = mysql_query($query) or die("Error" . mysql_error()); while ($row = mysql_fetch_array($result)) { $counter = 1; ?> <tr> <td> <? echo $row['firstname'] . " ". $row['midname'] . " " . $row['lastname'] . "<br>"; echo $row['address'] . " " . $row['address2'] . " <br>"; echo $row['town'] . " " . $row['county'] . "<br>"; echo $row['postcode'] . "<br>"; echo $row['telephone'] . " / " . $row['mobile'] . "<br>"; echo $row['contactname1'] . " " . $row['contactnumber1'] . "<br>"; echo $row['contactname2'] . " " . $row['contactnumber2'] . "<br>"; echo "DOB: " . $row['dob']; $counter++ ?> </td> <td> <? echo $row['firstname'] . " ". $row['midname'] . " " . $row['lastname'] . "<br>"; echo $row['address'] . " " . $row['address2'] . " <br>"; echo $row['town'] . " " . $row['county'] . "<br>"; echo $row['postcode'] . "<br>"; echo $row['telephone'] . " / " . $row['mobile'] . "<br>"; echo $row['contactname1'] . " " . $row['contactnumber1'] . "<br>"; echo $row['contactname2'] . " " . $row['contactnumber2'] . "<br>"; echo "DOB: " . $row['dob']; $counter++ ?> </td> <? } ?> </tr> </table> </body> i cant show you the actual output page, as it has details of my studetns on it. but i think i have explained it enough. i appreciate the help so if you dont get what i mean, please contact me. Regards
×
×
  • 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.