ID:167336
 
I've read through the tutorials on BYONDScape and digitalBYOND telling me how to use a MySQL Database with DMCGI.
For the most part, they were all useful. But I've noticed, they only covered how to do a statement like this:
SELECT value FROM row

That serves the point for something small, but my query is, how do I make it use a "wildcard"(not sure on proper termonolgy) value.
For instance, the SQL string would look like this:
SELECT * FROM row


So I could assign variables to corrispond with the different rows and throw them in a while() loop until the query finishes and all necessary data is displayed on a page.
I could do it using the method above, but that would require, 5 times the amount of code I should need to use <.<

I thought that MySQL handled the *, not DMCGI(Or whatever CGI). It should handle it just like PHP, I believe, I have not tested it though.
In response to Scoobert
Uhh- yeah. Those are all MySQL queries, DM does nothing but tell MySQL the query.
In response to Crashed
var/ok
var/DBConnection/dbcon = new(DBI,DB_USER,DB_PASSWORD,Default_Cursor)
ok=dbcon.Connect()
content_type = "text/html"
if(!ok)
usr << "failed:[dbcon.ErrorMsg()]!"
else
var/DBQuery/qry = dbcon.NewQuery()
var/sql = "SELECT title FROM news"
ok = qry.Execute(sql)

while(qry.NextRow())
usr << qry.item[1]

dbcon.Disconnect()


That is the code I use. Notice the sql variable.
That displays all the data from the title row.
But, that is no good to me on it's own. I need content, date and all that junk inside the table itself.
So, how do I use a normal statement like:
SELECT * FROM news

In PHP the statement would be:
<?
$query = mysql_query("SELECT * FROM `news`") or die(mysql_error());
while($row=mysql_fetch_array($query))
{
echo("Title: " . $row['title'] . "<br>Date: " . $row['date']); //etc
}
?>

If I use the same code above, using my new statement, I get a nice value of 1.
In response to Tiberath
i think he is asking how the result-set from a wildcard SQL statement gets stored in DM - in PHP it can come back as an array, or multi-dimensional array.

would DM stuff it in a list?
In response to Tiberath
Nadrew recently updated Dantom.DB to include a new function that will let you do data["title"].

To do it your way you'd have to do data[1], data[2], etc.


ID:431640
In response to DarkView
I really need to update the documentation for that, I can probably work something up with the hordes of freetime I'll have not being able to come online for more than an hour a day.(stupid internet company wanting money...)
In response to Nadrew
Nadrew wrote:
(stupid internet company wanting money...)

Those fiends.