22-12-2004, 17:09
|
|
|
|
חבר מתאריך: 09.04.02
הודעות: 8,000
|
|
מה לא טוב בקודים האלה:
זה בעקרון קוד שאמור להתחבר למסד ולהציג את הנתונים שיש במסד...
זה הקוד התחברות למסד
קוד PHP:
<?php $mysql_link=mysql_connect('host','username','passw ord') or die("ERROR: cannot connect to MySQL server."); echo "connected successfully to MySQL server."; echo "MySQL error ($errno): ".mysql_error($mysql_link); if (mysql_select_db('shiridor_uk_db',$mysql_link)) echo "DB selected."; else echo "Could not select the DB."; ?>
וזה הקוד שמדפיס את תוכן המסד
קוד PHP:
<?php include "grade_connect.php"; //connecting to MySQL server and DB //building the sql query: $grade_show_query="SELECT * FROM ".$grade_course_table; $grade_result=@mysql_query($grade_show_query,$grad e_con) or die("<BR><B>ERROR:</B> error occured in mysql query.<BR>"); //execute the query or exit on failure //display table of the students and thier grades: ?> <TABLE border=1 cellpadding=2 cellspacing=2> <TR> <TH width=200 align="center">ערך</TH> <TH width=150 align="center">תת ערך 1</TH> <TH width=150 align="center">תת ערך 2</TH> <TH width=150 align="center">תת ערך 3</TH> </TR> <? //printing all the rows of the students: while ($grade_row=mysql_fetch_array($grade_result)) //as long as there are rows in the result { echo "<TR>"; echo "<TD align=\"right\"><B>".$grade_row["id_number"]."</B></TD>"; echo "<TD align=\"center\">".(($grade_row["grade_1"]!=null)?$grade_row["grade_1"]:"---")."</TD>"; echo "<TD align=\"center\">".(($grade_row["grade_2"]!=null)?$grade_row["grade_2"]:"---")."</TD>"; echo "<TD align=\"center\"><B>".(($grade_row["grade_final"]!=null)?$grade_row["grade_final"]:"---")."</B></TD>"; echo "</TR>"; } ?>
|