Most efficient code plz | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Most efficient code plz

Could someone plz help me to figure out the simplest "if" or "If/else" or whatever would be the most simplest way to code this https://code.sololearn.com/wiRIgGIn3P8l/#php what im trying to to is execute the first statement, but if the first statement returns no valid result echo "no posts in DB" (or something similar) but if it does then continue to the second statement and basically the same thing, if no result is returned just echo a message. Do i first have to do q query to see if each statement will fetch a valid result, or is the a way to write it as im trying to accomplish , as if first statement gives valid return, continue to next if next statement has no valid return then stop after first statement? I hope I am making this understandable, sorry if it is hard to follow. Thank you anyone that is taking time to look at what im asking. (edit: I was just thinking would a switch statement be appropriate? if so could someone provide a bit of guidance on how to write it.?)

19th Jun 2020, 1:54 AM
Mattit Yahu
Mattit Yahu - avatar
2 Answers
0
You can't get any results this way because user_id is a variable, you shouldn't include it in the static string.
19th Jun 2020, 7:58 AM
Gordon
Gordon - avatar
0
I did not include the entire page of code, just the lines in question. And Yes i get results fine, as long as there is info in the database, the line to retrieve posts is ok, because the way it is coded a user will not reach it if there are no posts, im just trying to figure out how to write it so if there are no comments yet a null array value error is not returned
21st Jun 2020, 7:05 PM
Mattit Yahu
Mattit Yahu - avatar