Jump to content
xisto Community
Tramposch

Retrieving Student Data By Student Id

Recommended Posts

There is a student record system that outputs data for a student, but it only outputs data for one user. Each user has a number at the end of the url.

/more2.html?frn=0011472

that is the end of the URL, what I want to do is output all of the users (just basically a range of the numbers) onto one page with php.

Could someone assist me?

Thanks.

Share this post


Link to post
Share on other sites

you need a loop to do a range of id numbers, or a better mysql query method.Post your code, please.

Share this post


Link to post
Share on other sites

you can use loops and mysql query to call the data from your database. it should be something like this:

$stusql ="SELECT * FROM  tablename WHERE (here you can write a condition for calling the fields by using id or maybe any other field you want)";$sturesult = mysql_query($stusql);$i =1;While ($sturow =mysql_fetch_assoc($sturesult)) {Echo "here you can specify which fields to be printed";}$i++;

but i think you should post your code so that we can help you.
Edited by web_designer (see edit history)

Share this post


Link to post
Share on other sites

You can reduce the number of results using the MySQL LIMIT clause. Here is the syntax for the LIMIT clause:

LIMIT {[offset,] row_count | row_count OFFSET offset}


However, that is much simpler than it looks. Example:

SELECT `username` FROM table_name LIMIT 0 , 100


You can replace 0 with the page number, minus 1, multiplied by the number of users you want and replace 100 with the number of users you want; just make sure they really are a number before making the query.

For performance reasons, you should always try to limit the amount of database queries. Here's an example to retrieve the number of rows within a table:

$sql = "SELECT COUNT(*) FROM table";$result = mysql_query($sql);$num_of_rows = mysql_result($result, 0);

Share this post


Link to post
Share on other sites
<html><head><title>Student Name Here</title><script type="text/javascript">function alertwindow (directory, alerttype, frn) {	w = window.open("/"+directory+"/alerts/"+alerttype+"alert.html?frn="+frn, "alert", "toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,width=350,height=250");}function helpwindow (url) {	w = window.open(url, "help", "toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,width=570,height=500");}function helptext (text) {	window.status = text;	return true;}function $(id) {	return document.getElementById(id);}function flipVis(divID) {	if ($(divID).className == 'visible') {		$(divID).className = 'invisible';	} else {		$(divID).className = 'visible';	}}function maxlength( field, maxlimit ) {	if ( field.value.length >= maxlimit ) {		field.value = field.value.substring( 0, maxlimit-1 );		return false;	}}function noNumbers(e) {	var keynum, keychar, numcheck;	if(window.event) keynum = e.keyCode; // IE	else if(e.which) keynum = e.which; // Netscape/Firefox/Opera	keychar = String.fromCharCode(keynum);	numcheck = /\d/;	return !numcheck.test(keychar);}function onlyNumbers(e) {	return !noNumbers(e);}</script><script language="JavaScript" type="text/javascript" src="/admin/JavaScript/validate_date.js"></script><link rel="shortcut icon" href="/favicon.ico" ><script language="JavaScript">function newstudent() {	us=prompt("Student name:","");	if(us!=null) {		window.frames[0].document.forms[0].selectstudent.value=us;		window.frames[0].document.forms[0].submit();		}	} </script></head><frameset cols="208,*" border=0><frame src="/admin/students/more2.html?frn=0011472" name="menu"><frame src="quicklookup.html?frn=0011472" name="content"></frameset><noframes><body><p>This page is designed to be viewed by a browser which supportsNetscape's Frames extension.  Your browser does not support frames.</body></noframes></html>

Does that help, I'm sorry that I'm asking so much, I used to know php and stuff, but since school started I replaced PHP knowledge with school stuff knowledge that I don't remember. But i don't know how I would incorporate that into php, what that code is is one student info output on one page.Does.. that make sense :/Thanks

Share this post


Link to post
Share on other sites

Does that help, I'm sorry that I'm asking so much, I used to know php and stuff, but since school started I replaced PHP knowledge with school stuff knowledge that I don't remember. But i don't know how I would incorporate that into php, what that code is is one student info output on one page.

That's only HTML and JavaScript; these alone cannot do any database work. We can only provide general responses to your specific situation, as we do not have any idea how the database is structured, if even a MySQL database is being used to store the information you want to retrieve (you didn't state what database the student records are stored in), et cetera. If that is all you can provide, then i am afraid that we won't be able to provide any specific solutions, if at all anymore information. We could attempt to provide you with solutions that make assumptions that may not be true, but since they may not be true, it may be work in vain.

Share this post


Link to post
Share on other sites

well what im wondering.. instead of taking it from the database.. take it from the url..What i was planning is just a PHP script that took every URL, each student has a specific url which is specified by a number at the end of the URL, can you make a script that basically.. echoes the page for each student number, do you know what I mean?

Share this post


Link to post
Share on other sites

It sounds like it's not your website the one you're trying to pull the info.

Brilliant! ;)

 

So you need to use Snoopy class, a PHP class for fetching other websites content.

In the same directory to where you upload Snoopy.class.php, create this something.php file:

<?php	include "Snoopy.class.php";$firstID = 0; // this would be the first number of the range of students IDs$lastD = 20; // last number in the range$urlbase = "school.edu/more2.html?frn=&%2334;; // this would be the URL address of the website, but without the student ID number$i = $firstID;$snoopy = new Snoopy;echo "Beginning<p>";while ($i<=$lastID) {		$snoopy->fetchtext($urlbase . $i); // snoopy fetches the pages content	print $snoopy->results; // and prints it to the screen	$i++;}echo "<p>End."; // bye bye?>

Here's a basic idea of the kind of script you need, I think. But no warranties. It may hang up your server, the other server, or both.... I don't know if it works or not. And I'm not going to try it :P

At best, it will show the info you need, but quite messy.

Edited by andresf91 (see edit history)

Share this post


Link to post
Share on other sites

really i couldn't understand you well here, but i will explain some points here:

first: the code you posted had nothing to database,it is just javascript to styling the main page, adding frames...ect.
second: the number that appears in url, that's correct it is different for each student, because it is the result of (post and get action) in form. when you hit the submit button and you are reading data from database the id of that student will show in the link, or maybe it can be an online form entry and the result will show in link too.

but reading data from link?? i never heard about it before. if someone knows that there is such thing, please post here.

but, if you want to show student info from database, you should write something like this. assuming, you have a table in the database called studentinfo with three fiels (studentname, birth_date,age)

<?phpinclude("config.php");	mysql_pconnect($dbhost, $dbuname, $dbpw);		@mysql_select_db("$dbname") or die ("Unable to select database");$query="select * from studentinfo ";$result=mysql_query($query);mysql_close();/*Display Results*/$num=mysql_numrows($result);$i=0;while ($i < $num) {	$studentname=mysql_result($result,$i,"studentname");	$birth_date=mysql_result($result,$i,"birth_date");	$gender=mysql_result($result,$i,"gender");	$id=mysql_result($result,$i,"id");	?>  <table border="0" cellspacing="0" cellpadding="0">  <tr>	<td width="100%"><p><b>studentname :</b><i><? echo $studentname;?></i></p>	  <p><b>Birth_date :</b>  <i> <?echo $birth_date;?></i></p>	  <p><b>Gender :</b><i><?echo$gender;?></i></p>	  </td>  </tr></table><?	++$i;}?>

Share this post


Link to post
Share on other sites

mm the code is just a HTML with JS, you need to integrate it into a database so that you can make use of somedatabase query techniques, but I think there are any other methods,@web_designer codes was right so you can make use of it to integrate it into a database

Share this post


Link to post
Share on other sites

I'll talk to my teacher some more about it in three periods, he has access to the database I believe, so I guess we'll go from there. Andres idea seems like what I was looking for, I'm going to test that out, and if it doesn't work, I will look at the database ideas.Thanks.

Share this post


Link to post
Share on other sites

I'll talk to my teacher some more about it in three periods, he has access to the database I believe, so I guess we'll go from there. Andres idea seems like what I was looking for, I'm going to test that out, and if it doesn't work, I will look at the database ideas.

The method that you asked for, which andresf91 gave an example of, would put unnecessary stress on the server. I could not tell if this script would be placed on the same server or another one by your post, but in either case, this is the scenario that would occur: The script requests for entire page (i.e. the student page) to be rendered, the page gets the information from the database, parses the rest of the information and sends it to your script. Your script retrieves the information, parses the HTML searching for the information it wants, tossing out any information it doesn't need, and renders it. This process is multiplied by the number of students that are to be displayed. Having it on the same server would mean there is less time to wait to download the entire HTML page (i.e. more2.html?frn=<student number>), but the same amount of calls and processing power would be required. Say you wanted to show 15 students per page. That would be the equivalent of 15 people accessing the same student page from 15 different computers. You should not consider using this method.

Share this post


Link to post
Share on other sites

Truefusion has a point there. But if you don't have access to the database, then you obviously need to fetch it from the website. It's a kind of aggressive takeover, and I wouldn't recommend using Xisto's servers to do it.

Of course, once you've got the access to the database from your teacher, all the trouble of fetching from a link is unnecessary. If you're still interested in the option I described before, here's a brief description of Snoopy.

What is Snoopy?

 

Snoopy is a PHP class that simulates a web browser. It automates the

task of retrieving web page content and posting forms, for example.

 

Some of Snoopy's features:

 

* easily fetch the contents of a web page

* easily fetch the text from a web page (strip html tags)

* easily fetch the the links from a web page

* supports proxy hosts

* supports basic user/pass authentication

* supports setting user_agent, referer, cookies and header content

* supports browser redirects, and controlled depth of redirects

* expands fetched links to fully qualified URLs (default)

* easily submit form data and retrieve the results

* supports following html frames (added v0.92)

* supports passing cookies on redirects (added v0.92)

The thing is that, as truefusion said (and I said in my previous post) it may slow down both servers (the one in which is hosted the info and the one in which you're running this script). So if you tried to retrieve the info of 15 students it may take a while... but if we're talking about hundreds, then that can be a bit complicated. I mean, I don't think it will work before the server breaks down the connection for excessive amount of time to execute the script (that's something I hadn't taken into account before, sorry).

 

I guess that you need to be very proficient in PHP to get to retrieve the info you need from the website in intervals, mixing Snoopy class, cron, regular expression or some other way to separate the info you need from the rest of the pages.... and storing it in your own database of file... It's way too complicated yes, I can't even enunciate it.

Share this post


Link to post
Share on other sites

If you really don't want to work with the database, you can always write a script that writes it into a text file:

$filepath = "testFile.txt";$fh = fopen($filepath, 'w');$stringData = "Bobby Bopper\n";fwrite($fh, $stringData);$stringData = "Tracy Tanner\n";fwrite($fh, $stringData);fclose($fh);

and this would write it into the text file. You can then have PHP read the file and echo it back with fread().

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.