Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 136,481 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,733 people online right now. Registration is fast and FREE... Join Now!




How to DO this in PHP... I totally do not have the idea...

 
Reply to this topicStart new topic

How to DO this in PHP... I totally do not have the idea..., Lets say the contents from the databsae...

aco99
5 Mar, 2008 - 09:19 PM
Post #1

New D.I.C Head
*

Joined: 5 Mar, 2008
Posts: 9

Hi to all... this is simply my very first problem that I am about to consult with you guys...

This is totally not an assignment of mine or whatsoever I just need this to run my demo website for my CAI project that I am about to propose to my school....

Heres the situation...

I had a database here with fields
ID - ExamName - TopicCode - SubjectCode - ExamContents - Published

the main problem here is that I do not know what particular process am I going to use regarding the processing of the contents of the 'ExamContents' field and display the particular 'Question entry' from the database'...

lets say that ExamContents has this content...

1:4-7-12-16-18-25,3:25-54-67-90-105,2:38-43-72-87-90

1, the first character followed by a colon denotes the type of exam, lets say Identification and the numbers next to it separated by dashes were the 'IDs' from the question bank.... so is the second one 3: that denotes Modified True or false type and 2: denotes Debugging....

what my problem now is that I do not know what specific string functions are going to be used to make an output like these...
QUOTE

Identification:

QuestionItem that has the ID of 4
QuestionItem that has the ID of 7
QuestionItem that has the ID of 12
QuestionItem that has the ID of 16
QuestionItem that has the ID of 18
QuestionItem that has the ID of 25

Modified True of False:

QuestionItem that has the ID of 25
QuestionItem that has the ID of 54
QuestionItem that has the ID of 67
QuestionItem that has the ID of 90
QuestionItem that has the ID of 105

Debugging:

QuestionItem that has the ID of 38
QuestionItem that has the ID of 43
QuestionItem that has the ID of 72
QuestionItem that has the ID of 87
QuestionItem that has the ID of 90

I just guessed the following code to show this stuff
CODE

<?php

...
$result = mysql_query($query) or die('There was an error regarding the connection to the database. Please try again');

while ($row = mysql_fetch_assoc($result)) {

$QuestionSet = $row['QuestionContent'];

}

$QuestionContentSize = strlen($QuestionSet);
$StringIndex = 0;

while (isset($QuestionSet{$StringIndex})) {
    $data[$nr] = $string{$nr};
    $nr++;
}

for($i=$StringIndex;$i<$QuestionContentSize;$i++) {
    $query[$i] = "Select Question from exambank WHERE ID = '$data[$i]'";
    $result[$i] = mysql_query($query[$i]) or die('Unable to download questions. Try again.');

while ($row = mysql_fetch_assoc($result[$i])) {

   $Question = $row['Question'];

}
   echo '$Question';

}
?>




This is just I know but it is 100% sure it wont work...

I already can break down the string contents into an array but I do not know what it will do next when the array contents is a : or a - an a ,

Can someone revise this?

Please???

This post has been edited by aco99: 5 Mar, 2008 - 09:22 PM
User is offlineProfile CardPM
+Quote Post

SpaceMan
RE: How To DO This In PHP... I Totally Do Not Have The Idea...
6 Mar, 2008 - 05:52 AM
Post #2

D.I.C Regular
Group Icon

Joined: 20 Feb, 2003
Posts: 270


CODE

<?
echo $QuestionSet = '1:4-7-12-16-18-25,3:25-54-67-90-105,2:38-43-72-87-90';
echo '<br>';
$sections = explode(',',$QuestionSet);

foreach($sections as $idx => $val){
  $ids = explode(":",$val);
  $QuestionItems[$ids[0]] = explode('-',$ids[1]);
}

print_r($QuestionItems);

foreach($QuestionItems as $idx => $val){
    echo '<br>';
    echo $query[$idx] = 'Select Question from exambank WHERE ID = '.$idx;
    //$result[$idx] = mysql_query($query[$idx]) or die('Unable to download questions. Try again.');
}

?>


This post has been edited by SpaceMan: 6 Mar, 2008 - 06:23 AM
User is offlineProfile CardPM
+Quote Post

SpaceMan
RE: How To DO This In PHP... I Totally Do Not Have The Idea...
6 Mar, 2008 - 06:05 AM
Post #3

D.I.C Regular
Group Icon

Joined: 20 Feb, 2003
Posts: 270

i will read again later after i have had more coffee!!!!

seems i am missing something.

back, i think i see.. i will revise above code.

This post has been edited by SpaceMan: 6 Mar, 2008 - 06:17 AM
User is offlineProfile CardPM
+Quote Post

SpaceMan
RE: How To DO This In PHP... I Totally Do Not Have The Idea...
6 Mar, 2008 - 06:32 AM
Post #4

D.I.C Regular
Group Icon

Joined: 20 Feb, 2003
Posts: 270

revised it a bit to show the aditional arrays.
simulation, a bit difficult to do with out live data.
but this maybe all you needed.

php

<?
echo $QuestionSet = '1:4-7-12-16-18-25,3:25-54-67-90-105,2:38-43-72-87-90';
echo '<br>';
$sections = explode(',',$QuestionSet);

foreach($sections as $idx => $val){
$ids = explode(":",$val);
$QuestionItems[$ids[0]] = explode('-',$ids[1]);
}

print_r($QuestionItems);

foreach($QuestionItems as $idx => $val){
echo '<br>';
echo $query[$idx] = 'Select Question from exambank WHERE ID = '.$idx;
//$result[$idx] = mysql_query($query[$idx]) or die('Unable to download questions. Try again.');
foreach($val as $id => $value)
echo '<br>QuestionItem='.$value.' ';

}

?>


output,
1:4-7-12-16-18-25,3:25-54-67-90-105,2:38-43-72-87-90
Array ( [1] => Array ( [0] => 4 [1] => 7 [2] => 12 [3] => 16 [4] => 18 [5] => 25 ) [3] => Array ( [0] => 25 [1] => 54 [2] => 67 [3] => 90 [4] => 105 ) [2] => Array ( [0] => 38 [1] => 43 [2] => 72 [3] => 87 [4] => 90 ) )
Select Question from exambank WHERE ID = 1
QuestionItem=4
QuestionItem=7
QuestionItem=12
QuestionItem=16
QuestionItem=18
QuestionItem=25
Select Question from exambank WHERE ID = 3
QuestionItem=25
QuestionItem=54
QuestionItem=67
QuestionItem=90
QuestionItem=105
Select Question from exambank WHERE ID = 2
QuestionItem=38
QuestionItem=43
QuestionItem=72
QuestionItem=87
QuestionItem=90

This post has been edited by SpaceMan: 6 Mar, 2008 - 06:36 AM
User is offlineProfile CardPM
+Quote Post

aco99
RE: How To DO This In PHP... I Totally Do Not Have The Idea...
6 Mar, 2008 - 05:31 PM
Post #5

New D.I.C Head
*

Joined: 5 Mar, 2008
Posts: 9

Wow... ok ill be testing this code hmm better cross my fingers!!!! HAHAHA Thanks.... Ill be posting the FINISHED PRODUCT LATER!!!
User is offlineProfile CardPM
+Quote Post

aco99
RE: How To DO This In PHP... I Totally Do Not Have The Idea...
10 Mar, 2008 - 09:51 PM
Post #6

New D.I.C Head
*

Joined: 5 Mar, 2008
Posts: 9

Hey can I simply 'RANDOMIZE' the array contents? because Everytime I do that the ID number changes!
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 06:57PM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month