开发者

Selecting a yet unknown DB table with php mysql

开发者 https://www.devze.com 2023-02-13 00:36 出处:网络
My problem is i dont know what db table i need to connect to until i have performed the first query. the image_library and text_library tables both have differen开发者_如何学运维t fields.

My problem is i dont know what db table i need to connect to until i have performed the first query. the image_library and text_library tables both have differen开发者_如何学运维t fields.

I currently have it working with if else statements but feel there a better way to do this.

I want to be able to add library's in the future, so this method doesn't seem to be modularized enough.

$obj_results = mysql_query("SELECT library_sets.library_table FROM objects
LEFT JOIN library_sets ON library_sets.id=objects.library_set_id
WHERE objects.status_id='1' AND objects.block_id='$block_id' ORDER BY position ASC",$con_web) or die (mysql_error());
while($obj_rows=mysql_fetch_array($obj_results))
{
  $object_library_table=$obj_rows["library_table"];

  if($object_library_table=="image_library")
  {
    connect to db table with specific select statement
  }
    else if($object_library_table=="text_library")
  {
    connect to db table with specific select statement
  }
}

Thanks


You could try using the MySQL control structures to do that in just one query: http://dev.mysql.com/doc/refman/5.0/en/control-flow-functions.html

0

精彩评论

暂无评论...
验证码 换一张
取 消