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

Lets say the contents from the databsae...

Page 1 of 1

5 Replies - 666 Views - Last Post: 10 March 2008 - 10:51 PM Rate Topic: -----

#1 aco99  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 05-March 08

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

Posted 05 March 2008 - 10:19 PM

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
<?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: 05 March 2008 - 10:22 PM


Is This A Good Question/Topic? 0
  • +

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

#2 SpaceMan  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 10
  • View blog
  • Posts: 507
  • Joined: 20-February 03

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

Posted 06 March 2008 - 06:52 AM

<?
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: 06 March 2008 - 07:23 AM

Was This Post Helpful? 0
  • +
  • -

#3 SpaceMan  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 10
  • View blog
  • Posts: 507
  • Joined: 20-February 03

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

Posted 06 March 2008 - 07:05 AM

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: 06 March 2008 - 07:17 AM

Was This Post Helpful? 0
  • +
  • -

#4 SpaceMan  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 10
  • View blog
  • Posts: 507
  • Joined: 20-February 03

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

Posted 06 March 2008 - 07:32 AM

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.

<?
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: 06 March 2008 - 07:36 AM

Was This Post Helpful? 0
  • +
  • -

#5 aco99  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 05-March 08

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

Posted 06 March 2008 - 06:31 PM

Wow... ok ill be testing this code hmm better cross my fingers!!!! HAHAHA Thanks.... Ill be posting the FINISHED PRODUCT LATER!!!
Was This Post Helpful? 0
  • +
  • -

#6 aco99  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 05-March 08

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

Posted 10 March 2008 - 10:51 PM

Hey can I simply 'RANDOMIZE' the array contents? because Everytime I do that the ID number changes!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1