0

Hello, a noob in web programming here. Doing some course related database, would appreciate any help :), I want to ask whether any of you can help me on how to retrieve get data from mysql using php function, but separate each data from mysql one by one, cause i want the query done by my php function be a draggable object, my function look like this:

<?php
$q=$_GET["q"];
$sql_fundamental_g= "SELECT mf_mname, mfg_group_name, credits
FROM major_fundamental_g, major_fundamental, course, course_group
WHERE mf_mname =  '".$q."'
AND mfname = mfg_mfname
AND course_group_name = mfg_group_name
AND course_group_name = code";

$result = mysql_query($sql_fundamental_g);

echo "<b>Major Fundamental Courses</b><br>";

echo "<br><br>Student who major in ".$q." should take all of the following :<br>";

echo "<table border='1'>
<tr>
<th>Major</th>
<th>code</th>
<th>credits</th>
</tr>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['mf_mname'] . "</td>";
  echo "<td>" . $row['mfg_group_name'] . "</td>";
  echo "<td>" . $row['credits'] . "</td>";
  echo "</tr>";
  }
echo "</table>";
mysql_close($con);
?>

and in this result i get the whole table, but i'm wondering if i can generate row by row ,cause i wanna use each row as separate entity and make them a draggable object using ajax later on
Thanks a lot :)

3
Contributors
5
Replies
11
Views
5 Years
Discussion Span
Last Post by confstu
2

mysql_fetch_array returns a row of the table in a form of an array. You actually are processing row by row already in the code:

while($row = mysql_fetch_array($result))

Within the above while loop you can do anything with the row or the fields of the row.

Can you please explain more in detail what you want to achieve (I hope I did not missunderstand your question).

0

Thx so much for the reply broj1, oh maybe i didn't give clear explanation before, you could take a look of my html code:

<html>
<head>


<script type="text/javascript">
function allowDrop(ev)
{
ev.preventDefault();
}

function drag(ev)
{
ev.dataTransfer.setData("Text",ev.target.id);
}

function drop(ev)
{
ev.preventDefault();
var data=ev.dataTransfer.getData("Text");
ev.target.appendChild(document.getElementById(data));
}
</script>


<script type="text/javascript">

// function to get course for major 
function CurrentSelections(str) 
  {
if (str=="")
  {
  document.getElementById("txtHint").innerHTML="";
  return;
  } 
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","getcourse.php?q="+str,true);
xmlhttp.send();

}   

</script>
</head>

<body>


<div id="txtHint"  draggable="true" ondragstart="drag(event)" width="100" height="100" >imported course from database will be listed here...</div>


</body>
</html>

basically what i want to show in html is the "txtHint" and my function CurrentSelections(str) get the php file, and show all the table, because i am using another function to drag the table, when i execute the code i end up dragging the whole table, but what i wanted is to just drag one row of the data from the table.and i don't know how to do it. Thanks again for your reply

2

OK so you want to drag the rows of displayed html table. This is a Javascript job. Have you checked the link pritaeas sent in above post? I think this is the answer for you (have a look at the code in the browser - you will find the css and javascript you need).

Votes + Comments
thanks once again, i will see pritaeas link and try it
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.