Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+1 vote
851 views
in Q2A Core by

Hey,

I have an external php file where I

require_once '../qa-include/qa-base.php';

So far I want to get all the questions from my db (in my case only 1 in there) and return it to my self created html page.

I have trouble finding the right function inside the Q2A structure which would return me this result. Can you please put me on the right track?

Furthermore it would be very kind if you could also give me an example on how to query the db in a specific way, if this is not to much to ask.

Regards,

Peter

Q2A version: latest

1 Answer

+1 vote
by
selected by
 
Best answer

AFAICS Question2Answer has pagination already built into the code that fetches questions, so you're probably better off running your own queries via the function qa_db_query_raw() (located in qa-include/qa-db.php). All posts are stored in the table qa_posts (questions with the type "Q," answers with the type "A," and comments with the type "C").

To get a list of all questions with their ID and title from the DB you could run something like this:

$query  = "SELECT postid, title FROM qa_posts WHERE type='Q'";
$result = qa_db_query_raw($query);

Use the methods of the resulting mysqli_result object to retrieve the data, e.g.

$questions = $result->fetch_all();

which will return the entire data set as a jagged array (i.e. an array of arrays).

by
Thank you for your help. After I tried it I was able to get it out as a var_dump().

This is how it looks like.

object(mysqli_result)#3 (5) {
  ["current_field"]=>
  int(0)
  ["field_count"]=>
  int(2)
  ["lengths"]=>
  NULL
  ["num_rows"]=>
  int(1)
  ["type"]=>
  int(0)
}

As I am new to Programmin I have no idea how to get the data out correctly and furthermore I am not even sure if there is any data. Any hints on how to get what I want? Thank you
by
edited by
Since you're apparently struggling with something basic as handling a mysqli_result object (https://www.php.net/manual/en/class.mysqli-result.php) you seem to be way out of your depth here. I updated my answer with some additional information, but I recommend you pick up a PHP book or tutorial and learn the fundamentals first.
by
Yes I am fairly new to PHP and learning on the fly. Thank you for your help!
by
Ansgar, may I bother you one more time. I come along quite well but now I want to create a URL - Link for every question in that database. Basically I want to add a url a user could klick to get redirected to the q2a platform and see the complete question. Is such a thing possible? Thank you
by
That is a different question, so please ask a new question.
...